错误0x80131047正在加载MySQL Connector DLL

时间:2016-09-18 16:44:06

标签: mysql macos powershell .net-core powershell-core

PowerShell刚刚开源(v6.0.0-alpha.10),我就是 试图让它从OS X连接到MySQL实例。

Oracle似乎建议(如果我正确地阅读它)他们有一个 .Net核心连接器 here。 我像这样运行安装:

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

并且输出看起来很好:

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

当我尝试像这样加载程序集时:

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

我收到以下错误(请注意,我使用了一个传递路径 变量$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

关于变通方法/解决方案的任何想法?我意识到PowerShell仍然存在 阿尔法。

修改

我能够使用以下两个命令安装MySQL提供程序:

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

我尝试注册我能想到的所有程序集:

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 

但是,当尝试创建一个新的MySql对象时,它仍然会爆炸 这样:

  

New-Object:找不到类型[MySql.Data.MySqlClient]:   验证是否已加载包含此类型的程序集。

2 个答案:

答案 0 :(得分:1)

这不是一个.NET核心库 - 这个词"核心"这里表示EF6和Web包之间共享的功能,并且介绍了.NET Core。

实体框架核心在撰写本文时正在开发MySql库。

答案 1 :(得分:0)

<强>解

所以,事实证明我在(大部分)正确的轨道上。 需要加载所有的DLL。通过将它们复制到自己的目录中来简化生活,然后通过遍历每个目录来加载它们:

将DLL复制到新位置

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

加载所有必需的DLL

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