我试图嫁给Unity3d和NHibernate。经过大量的魔术之后,它可以在编辑器中运行,但在Windows独立版.exe。
中崩溃我拥有的主要数据访问库:
MySql.Data.dll
I18N.dll
I18N.West.dll
System.Data.dll (2.0.5, for Unity)
NHibernate.dll (3.4.0)
win app启动时的崩溃是:
TypeLoadException: Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'NHibernate'.
at NHibernate.Driver.MySqlDataDriver..ctor () [0x00000] in d:\Downloads\nh\NHibernate-3.4.0.GA-src\src\NHibernate\Driver\MySqlDataDriver.cs:27
......... omitted System.Reflection chain .......
at NHibernate.Connection.ConnectionProvider.ConfigureDriver (IDictionary`2 settings) [0x00020] in d:\Downloads\nh\NHibernate-3.4.0.GA-src\src\NHibernate\Connection\ConnectionProvider.cs:107
Rethrow as HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver, NHibernate, Version=3.4.0.0, Culture=neutral, PublicKeyToken=null.
at NHibernate.Connection.ConnectionProvider.ConfigureDriver (IDictionary`2 settings) [0x00052] in d:\Downloads\nh\NHibernate-3.4.0.GA-src\src\NHibernate\Connection\ConnectionProvider.cs:113
at NHibernate.Connection.ConnectionProvider.Configure (IDictionary`2 settings) [0x0004f] in d:\Downloads\nh\NHibernate-3.4.0.GA-src\src\NHibernate\Connection\ConnectionProvider.cs:64
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider (IDictionary`2 settings) [0x000bd] in d:\Downloads\nh\NHibernate-3.4.0.GA-src\src\NHibernate\Connection\ConnectionProviderFactory.cs:50
由于无法加载System.Data.Common.DbProviderFactories,我认为它无法获取System.Data。同时我的System.Data被100%清楚地加载,因为还有另一个认证代码,它可以直接与DB完美配合,不涉及NHibernate。
是不是因为 NHibernate是使用.Net Framework Visual Studio配置文件中的System.Data构建的,而Unity项目使用的是2.0.5版本?
我尝试使用来自" Unity 3.5 .net完整基类库"的System.Data构建NHibernate。它已成功构建,但当我将System.Data.dll插入插件时,Unity也会崩溃:
InvalidProgramException: Invalid IL code in System.Data.Common.DbConnectionStringBuilder:Remove (string): IL_0000: ret
奇怪的是,Unity不应该从c:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v3.5 \ Profile \ Unity Full v3.5读取libs \ System.Data.dll中?
同时,我无法使用c:\ Program Files(x86)\ Unity \ Editor \ Data \ Mono \ lib \ mono \ unity \ System.Data.dll构建NHibernate。默认情况下,它从GAC加载v2.0.0。当我尝试在.csproj中显式编写2.0.5版本时,它失败了:
Warning 2 The primary reference "System.Data, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 processorArchitecture=x86" could not be resolved because it has an indirect dependency on the .NET Framework assembly "System.Transactions, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "2.0.5.0" than the version "2.0.0.0" in the current target framework. NHibernate
我绝望了 - 我应该如何构建NHibernate以及使用哪些库来使其在Unity中运行?
希望,有人有答案。 提前致谢! 由良
答案 0 :(得分:1)
好吧,经过一周的定期尝试,我终于让它发挥作用了:
那就是它。
我仍然想知道为什么Unity无法接受来自"" Unity 3.5 .net完整基类库" .Net简介,但至少它不会阻止我。