我一直試圖讓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):
- 創建.NET 4.0的控制檯應用程序
- 加入(例如,通過的NuGet)
- 參考,Autofac 3.0.1創建
ContainerBuilder
類 - 構建康壽的一個實例權證申請
- 運行在Mono下的控制檯應用程序
有沒有人對如何解決這個問題的想法?
我做了一些更多的測試,並建立了Autofac.Core項目的.NET 4.0類庫的版本。現在,當我構建這個版本並將我的測試項目鏈接到此版本的Autofac.dll(這是一個.NET 4.0庫,而不是一個可移植的類庫)時,Mono下的一切正常。 Mono不正確支持可移植類庫嗎? – 2013-02-27 14:05:30
經過對主題的進一步深入研究之後,事實證明,問題本身不是可移植類庫。它是便攜式類庫和擴展方法的結合。 Autofac庫定義了擴展方法,這會導致Mono 3.0.5失敗。我在這裏有一個repro這個問題:https://github.com/ErikSchierboom/monoportableclasslibraryextensionmethod – 2013-02-27 14:49:30
你能否把repro放入[Mono Bugzilla](http://bugzilla.xamarin.com/index.cgi)呢? – skolima 2013-02-27 23:25:42