Autofac 3.0 无法在 Mono 上运行

问题描述 投票:0回答:1

我一直在尝试让 Autofac 3.0.1 在 Mono 上运行,但到目前为止还没有成功。当我尝试在 Mono 3.0.5 上运行引用 Autofac 3.0.1 的应用程序时,出现以下异常:

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 method .ctor。我找到了有关此问题的一些信息,看来此问题是由于 ExtensionAttribute 类从一个 DLL 移动到另一个 DLL 所致:https://docs.lextudio.com/blog/how-to-use-nuget- on-mono-part-iv-65d6349aa5dc

这个问题可以重现如下(参见https://gist.github.com/ErikSchierboom/5047101):

  1. 创建 .NET 4.0 控制台应用程序
  2. 添加对 Autofac 3.0.1 的引用(例如通过 NuGet)
  3. 创建
    ContainerBuilder
    类的实例
  4. 构建控制台应用程序
  5. 在 Mono 下运行控制台应用程序

有人知道如何解决这个问题吗?

.net mono autofac
1个回答
1
投票

我在以下位置创建了此问题的重现: https://github.com/ErikSchierboom/monoportableclasslibraryextensionmethod 包含两个控制台应用程序和两个可移植类库。一 可移植类库定义一个方法作为扩展方法,另一个方法 没有。一个控制台应用程序使用扩展方法版本,并且 其他没有。要验证问题,请在 Mono 上运行两个控制台应用程序 3.0.5环境。使用扩展方法版本的会崩溃 而另一个则不会。

Mono 3.0.12 具有完整的 PCL 功能,可以防止此错误发生:http://www.mono-project.com/Release_Notes_Mono_3.0#New_in_Mono_3.0.12

© www.soinside.com 2019 - 2024. All rights reserved.