2013-02-27 73 views
3

我一直试图让Autofac 3.0.1在Mono上工作,但迄今为止一直不成功。当我尝试运行引用Autofac 3.0.1在Mono 3.0.5的应用程序,我得到以下异常:Autofac 3.0不能在Mono上运行

Mono: Assembly Loader probing location: '/opt/mono-3.0.5/lib/mono/4.5/mscorlib.dll'. 
Mono: Image addref mscorlib[0x14ce2c70] -> /opt/mono-3.0.5/lib/mono/4.5/mscorlib.dll[0x14ce1ec0]: 2 
Mono: Assembly Loader probing location: '/opt/mono-3.0.5/lib/mono/4.5/mscorlib.dll'. 
Mono: Assembly Loader loaded assembly from location: '/opt/mono-3.0.5/lib/mono/4.5/mscorlib.dll'. 
Mono: Assembly mscorlib[0x14ce2c70] added to domain ConsoleApplication1.exe, ref_count=1 
Mono: Assembly Loader probing location: 'ConsoleApplication1.exe'. 
Mono: Image addref ConsoleApplication1[0x14d20230] -> /var/www/sites/erik/monoconsole/ConsoleApplication1.exe[0x14d1f4a0]: 2 
Mono: Assembly ConsoleApplication1[0x14d20230] added to domain ConsoleApplication1.exe, ref_count=1 
Mono: Assembly Loader loaded assembly from location: 'ConsoleApplication1.exe'. 
Mono: Assembly Loader probing location: 'ConsoleApplication1.exe'. 
Mono: Assembly Ref addref ConsoleApplication1[0x14d20230] -> mscorlib[0x14ce2c70]: 2 
Mono: Assembly Loader probing location: '/var/www/sites/erik/monoconsole/Autofac.dll'. 
Mono: Image addref Autofac[0x14d269b0] -> /var/www/sites/erik/monoconsole/Autofac.dll[0x14d25c40]: 2 
Mono: Assembly Autofac[0x14d269b0] added to domain ConsoleApplication1.exe, ref_count=1 
Mono: Assembly Loader loaded assembly from location: '/var/www/sites/erik/monoconsole/Autofac.dll'. 
Mono: Assembly Ref addref ConsoleApplication1[0x14d20230] -> Autofac[0x14d269b0]: 2 
Mono: The request to load the retargetable assembly mscorlib v2.0.5.0 was remapped to mscorlib v4.0.0.0 
Mono: Assembly Ref addref Autofac[0x14d269b0] -> mscorlib[0x14ce2c70]: 3 
Mono: The request to load the retargetable assembly System.Core v2.0.5.0 was remapped to System.Core v4.0.0.0 
Mono: Assembly Loader probing location: '/opt/mono-3.0.5/lib/mono/gac/System.Core/4.0.0.0__7cec85d7bea7798e/System.Core.dll'. 
Mono: Assembly Loader probing location: '/var/www/sites/erik/monoconsole/System.Core.dll'. 
Mono: Assembly Loader probing location: '/opt/mono-3.0.5/lib/System.Core.dll'. 
Mono: Assembly Loader probing location: '/opt/mono-3.0.5/lib/mono/gac/System.Core/4.0.0.0__7cec85d7bea7798e/System.Core.exe'. 
Mono: Assembly Loader probing location: '/var/www/sites/erik/monoconsole/System.Core.exe'. 
Mono: Assembly Loader probing location: '/opt/mono-3.0.5/lib/System.Core.exe'. 
Mono: The following assembly referenced from /var/www/sites/erik/monoconsole/Autofac.dll could not be loaded: 
    Assembly: System.Core (assemblyref_index=1) 
    Version: 2.0.5.0 
    Public Key: 7cec85d7bea7798e 
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/var/www/sites/erik/monoconsole/). 

Mono: Failed to load assembly Autofac[0x14d269b0] 

Mono: Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. 
Missing method .ctor in assembly /var/www/sites/erik/monoconsole/Autofac.dll, type System.Runtime.CompilerServices.ExtensionAttribute 
Can't find custom attr constructor image: /var/www/sites/erik/monoconsole/Autofac.dll mtoken: 0x0a000015 
Hello! 
Mono: Unloading domain ConsoleApplication1.exe[0x2aaaab6f1cc0], assembly mscorlib[0x14ce2c70], ref_count=3 
Mono: Unloading domain ConsoleApplication1.exe[0x2aaaab6f1cc0], assembly ConsoleApplication1[0x14d20230], ref_count=1 
Mono: Unloading assembly ConsoleApplication1 [0x14d20230]. 
Mono: Unloading image /var/www/sites/erik/monoconsole/ConsoleApplication1.exe [0x14d1f4a0]. 
Mono: Unloading domain ConsoleApplication1.exe[0x2aaaab6f1cc0], assembly Autofac[0x14d269b0], ref_count=1 
Mono: Unloading assembly Autofac [0x14d269b0]. 
Mono: Unloading image /var/www/sites/erik/monoconsole/Autofac.dll [0x14d25c40]. 
Mono: Unloading assembly mscorlib [0x14ce2c70]. 
Mono: Unloading image /opt/mono-3.0.5/lib/mono/4.5/mscorlib.dll [0x14ce1ec0]. 

有几件事情要注意。首先,它似乎无法加载System.Core 2.0.5.0。这可能是由于Autofac 3.0.1是一个可移植的类库吗?

此问题也导致第二个问题,其中System.Runtime.CompilerServices.ExtensionAttribute中有一个Missing方法.ctor。我发现这个问题的一些信息,看来,这个问题是由于ExtensionAttribute类移动从一个DLL到另一个:http://www.lextm.com/2013/02/how-to-use-nuget-on-mono-part-iv.html

这个问题可以作如下复制(见https://gist.github.com/ErikSchierboom/5047101):

  1. 创建.NET 4.0的控制台应用程序
  2. 加入(例如,通过的NuGet)
  3. 参考,Autofac 3.0.1创建ContainerBuilder
  4. 构建康寿的一个实例权证申请
  5. 运行在Mono下的控制台应用程序

有没有人对如何解决这个问题的想法?

+0

我做了一些更多的测试,并建立了Autofac.Core项目的.NET 4.0类库的版本。现在,当我构建这个版本并将我的测试项目链接到此版本的Autofac.dll(这是一个.NET 4.0库,而不是一个可移植的类库)时,Mono下的一切正常。 Mono不正确支持可移植类库吗? – 2013-02-27 14:05:30

+0

经过对主题的进一步深入研究之后,事实证明,问题本身不是可移植类库。它是便携式类库和扩展方法的结合。 Autofac库定义了扩展方法,这会导致Mono 3.0.5失败。我在这里有一个repro这个问题:https://github.com/ErikSchierboom/monoportableclasslibraryextensionmethod – 2013-02-27 14:49:30

+0

你能否把repro放入[Mono Bugzilla](http://bugzilla.xamarin.com/index.cgi)呢? – skolima 2013-02-27 23:25:42

回答

1

我已经创建了此问题的重制: https://github.com/ErikSchierboom/monoportableclasslibraryextensionmethod它 包含两个控制台应用程序和两个可移植类库。一个 便携式类库将方法定义为扩展方法,而其他 不会。一个控制台应用程序使用扩展方法版本,而其他控制台则不使用。要验证该问题,请在Mono 3.0.5环境中运行这两个控制台应用程序。使用扩展方法版本的将崩溃 而另一个不会。

单3.0.12具有完全的PCL功能和防止此错误的发生:http://www.mono-project.com/Release_Notes_Mono_3.0#New_in_Mono_3.0.12

+0

如果您可以在问题列表中添加错误(尽管我不能保证我可以修复此错误),那将是非常棒的。 https://code.google.com/p/autofac/issues/list – 2013-03-20 15:40:57

+0

亚历克斯,我创建了以下错误:https://code.google.com/p/autofac/issues/detail?id=417&thanks=417&ts= 1363806624 – 2013-03-20 19:10:51

+0

我不确定要了解,您是否找到解决该问题的解决方法?看起来你连接的项目只是为了测试问题是否发生。不是吗?谢谢你的时间。 – ForceMagic 2013-12-10 20:38:26