Jeremy Jeremy - 1 month ago 11
MySQL Question

Error 0x80131047 loading MySQL Connector DLL


PowerShell has just been opened sourced (v6.0.0-alpha.10), and I'm
trying to get it to connect to a MySQL instance from OS X.

Oracle seems to suggest (if I'm reading it correctly) that they have a
.Net Core connector
here.
I ran the install like this:

Install-Package MySql.ConnectorNET.Entity -Destination /MySQL


and the output looked good:

Name                       Version Source Summary                

---- ------- ------ -------
MySql.ConnectorNET.Data 6.8.3.2 nugget ADO.Net driver for MySQL
MySql.ConnectorNET.Entity 6.8.3.2 nugget MySql Connector/NET for Entity Framework 6


When I try loading the assembly like this:

[System.Reflection.Assembly]::Load(/MySQL/MySql.ConnectorNET.Data.6.8.3.2/lib/net45/MySql.Data.dll)


I get the following error (note that I pass the path in with a
variable
$dll
):

Exception calling "Load" with "1" argument(s): "Could not load
file or assembly
'/MySQL/MySql.ConnectorNET.Entity.6.8.3.2/lib/net40/MySql.Data.dll,
Culture=neutral, PublicKeyToken=null'. The given assembly name or
codebase was invalid. (Exception from HRESULT: 0x80131047)" At
/development/scripts/test.ps1:28 char:1
+ [System.Reflection.Assembly]::Load("$dll")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException


Any ideas on a workaround / fix? I realize that PowerShell is still in
alpha.

EDIT

I was able to install the MySQL provider using these two commands:

Register-PackageSource -Name nuget.org -ProviderName NuGet -Location https://www.nuget.org/api/v2/
Install-Package MySql.Data.EntityFrameworkCore -Destination /Volumes/Main/libraries/MySQL/ -AllowPrereleaseVersions


I tried registering all the assemblies I could think of:

Microsoft.EntityFrameworkCore.1.0.1/lib/netstandard1.3/Microsoft.EntityFrameworkCore.dll
Microsoft.Extensions.Configuration.1.0.0/lib/netstandard1.1/Microsoft.Extensions.Configuration.dll
Microsoft.Extensions.Configuration.Json.1.0.0/lib/netstandard1.3/Microsoft.Extensions.Configuration.Json.dll
MySql.Data.EntityFrameworkCore.7.0.5-IR21/lib/netstandard1.6/MySql.Data.EntityFrameworkCore.dll
MySql.Data.7.0.5-IR21/lib/netstandard1.6/MySql.Data.dll


But, when trying to create a new MySql object, it still bombs out with
this:
New-Object : Cannot find type [MySql.Data.MySqlClient]:
verify that the assembly containing this type is loaded.



SOLUTION

posted down below

Answer

SOLUTION

So, it turns out I was on the (mostly) right track. All of the DLLs need to be loaded. Make life easier by copying them into their own directory, and then load them by iterating over each one:

copy the DLLs to a new location

Get-ChildItem "/Volumes/Main/libraries/mysql/*/lib/netstandard1.*/*.dll" | Copy-Item -Destination "/Volumes/Main/libraries/NEW_mysql" -Force

load all required DLLs

Get-ChildItem "/Volumes/Main/libraries/NEW_mysql" | ForEach-Object {
$path = "/Volumes/Main/libraries/NEW_mysql/" + $_.Name
Add-Type -Path $path -PassThru | Out-Null
}