Skip navigation links

MySQL Forums :: Connector/NET and C#, Mono, .Net :: Could not load file or assembly MySql.Data.dll 0x80131515


Advanced Search

Could not load file or assembly MySql.Data.dll 0x80131515
Posted by: Daniel Ratliff ()
Date: August 16, 2013 06:19AM

Hello,

I have written a PowerShell script to connect to a MySQL database to query for some information. I am using the extracted MySQL.data.dll and the script works fine, if .NET Framework 4.5 is installed. If the machine only has .NET Framework 4.0 installed, I get the below error.

add-type : Could not load file or assembly 'file:///P:\MySql.Data.dll' or
one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At P:\printer.ps1:75 char:5
+ add-type -Path "$PWD/MySql.Data.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand

The target environment is Win7 x64. I have been searching online for the last few days and found no reference that .NET Framework 4.5 was required. I am using PowerShell 3.0 but I would have thought one of the other .dlls would have worked. I have tried using the v2.0, v4.0, and v4.5 dlls to no avail. See below for the entire script.

[environment]::CurrentDirectory = Get-Location -PSProvider FileSystem
write-host "Changing directory to:"([environment]::currentdirectory) -ForegroundColor Yellow

function global:PrinterList {
Param(
[string]$printerip
)

$mysqlserver = "server"
$mysqldb = "db"
$mysqluser = "user"
$mysqlpassword = 'pass'
$mysqlconnectionstring = "Server=$mysqlserver; Database=$mysqldb; User=$mysqluser; Password=$mysqlpassword"

$mysqlquery = "
SELECT Model,IP,Building,Floor,Printer_ID
FROM printers
WHERE ip = '$printerip'"

#[void][System.Reflection.Assembly]::LoadFrom(".\MySql.Data.dll")
add-type -Path ".\MySql.Data.dll"

$connection = New-Object MySql.Data.MySqlClient.MySqlConnection
$connection.ConnectionString = $mysqlconnectionString
$connection.Open()
$command = New-Object MySql.Data.MySqlClient.MySqlCommand($mysqlquery, $connection)
$dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command)
$global:mysqltable = New-Object System.Data.DataTable
$recordCount = $dataAdapter.Fill($mysqltable)
$global:mysqltable
}

Any ideas? Is installing .NET Framework 4.5 my only option?

Options: ReplyQuote


Subject Written By Posted
Could not load file or assembly MySql.Data.dll 0x80131515 Daniel Ratliff 08/16/2013 06:19AM
Re: Could not load file or assembly MySql.Data.dll 0x80131515 Gabriela Martinez Sanchez 08/16/2013 09:05AM
Re: Could not load file or assembly MySql.Data.dll 0x80131515 Daniel Ratliff 08/16/2013 03:19PM
Re: Could not load file or assembly MySql.Data.dll 0x80131515 Gabriela Martinez Sanchez 08/16/2013 03:23PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.