我下载了mysql-connector-net-6.4.3-noinstall.zip,解压缩并将mysql.data.dll重命名为MySql.Data.dll:
$ cd v2/
$ ls
mysql.data.cf.dll mysql.data.dll mysql.data.entity.dll mysql.visualstudio.dll mysql.web.dll
$ mv mysql.data.dll MySql.Data.dll
$ sudo gacutil /i MySql.Data.dll
Password:
Installed MySql.Data.dll into the gac (/Library/Frameworks/Mono.framework/Versions/2.10.4/lib/mono/gac)
我在/Library/Frameworks/Mono.framework/Versions/2.10.4/lib/mono/2.0中创建一个符号链接到MySql.Data.dll:
$ sudo ln -s ../gac/MySql.Data/6.4.3.0__c5687fc88969c44d/MySql.Data.dll MySql.Data.dll
在/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig中创建一个包配置文件,以便我可以从MonoDevelop引用包:
Name: MySql.Data
Description: MySql.Data
Version: 6.4.3.0
Libs: -r:/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/2.0/MySql.Data.dll
然后我创建一个新的控制台项目,添加对MySql.Data和build的引用。编译器失败,出现以下异常:
Unhandled Exception: System.IO.FileLoadException: The assembly name is invalid.
at System.Reflection.AssemblyName..ctor (System.String assemblyName) [0x00000] in <filename unknown>:0
at Mono.CSharp.ImportedAssemblyDefinition.ReadAttributes () [0x00000] in <filename unknown>:0
at Mono.CSharp.MetadataImporter.GetAssemblyDefinition (System.Reflection.Assembly assembly) [0x00000] in <filename unknown>:0
at Mono.CSharp.ReflectionImporter.ImportAssembly (System.Reflection.Assembly assembly, Mono.CSharp.RootNamespace targetNamespace) [0x00000] in <filename unknown>:0
at Mono.CSharp.DynamicLoader.LoadReferences (Mono.CSharp.ModuleContainer module) [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileLoadException: The assembly name is invalid.
at System.Reflection.AssemblyName..ctor (System.String assemblyName) [0x00000] in <filename unknown>:0
at Mono.CSharp.ImportedAssemblyDefinition.ReadAttributes () [0x00000] in <filename unknown>:0
at Mono.CSharp.MetadataImporter.GetAssemblyDefinition (System.Reflection.Assembly assembly) [0x00000] in <filename unknown>:0
at Mono.CSharp.ReflectionImporter.ImportAssembly (System.Reflection.Assembly assembly, Mono.CSharp.RootNamespace targetNamespace) [0x00000] in <filename unknown>:0
at Mono.CSharp.DynamicLoader.LoadReferences (Mono.CSharp.ModuleContainer module) [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
我也尝试使用相同的结果直接引用程序集。
有什么建议吗?
我可以将我的项目定位到.NET Framework v2.0并使用gmcs构建OK,但不能使用dmcs构建.NET 3.5或4.0。
答案 0 :(得分:3)
更新:我升级到单声道2.10.5。我能够为.NET / Mono加载版本6.4.4.0的MySql连接器。似乎现在正在运作。
我修改了mcs,以便在编译期间通过“-r”加载时显示AssemblyName值。在这种情况下,我使用的是连接器版本6.3.7.0和单声道版本2.10.4。
mcs Main.cs -r:System.Data.dll -r:/usr/lib/mono/4.0/MySqlData.dll
Unhandled Exception: System.IO.FileLoadException: The assembly name is invalid: MySql.Data.Tests, PublicKey = 0024000004800000940000000602000000240000525341310004000001000100d973bda91f71752c78294126974a41a08643168271f65fc0fb3cd45f658da01fbca75ac74067d18e7afbf1467d7a519ce0248b13719717281bb4ddd4ecd71a580dfe0912dfc3690b1d24c7e1975bf7eed90e4ab14e10501eedf763bff8ac204f955c9c15c2cf4ebf6563d8320b6ea8d1ea3807623141f4b81ae30a6c886b3ee1
at System.Reflection.AssemblyName..ctor (System.String assemblyName) [0x00000] in <filename unknown>:0
at IKVM.Reflection.AssemblyName..ctor (System.String assemblyName) [0x00000] in <filename unknown>:0
at Mono.CSharp.ImportedAssemblyDefinition.ReadAttributes () [0x00000] in <filename unknown>:0
看起来名称不匹配(“MySql.Data”与“MySql.Data.Tests”)。
答案 1 :(得分:0)
要检查的事项:确保MySQL连接器不是使用32位或64位设置构建的,之前我遇到过其他程序集的问题。其次,检查MySQL.Data.dll本身的所有依赖项。不幸的是,Mono没有显示装配名称。它可能试图加载其中一个依赖项。