当 Linker 配置为 Link All 时,Autofac Build() 在最新的 Xamarin iOS 上抛出异常
Autofac Build() throws exception on latest Xamarin iOS when Linker configured to Link All
升级到 Visual Studio 16.3.0 后(Visual Studio for Mac 8.3.1805)Autofac 在以前工作的项目中执行 builder.Build()
时抛出异常:
The type 'Autofac.Features.Indexed.KeyedServiceIndex'2' does not
implement the interface 'Autofac.Features.Indexed.IIndex'2'
对于 Visual Studio 的这个版本(可能还有更早的版本),iOS 是使用 Mono 6.4.0.198 编译的,我怀疑这可能是引入制动变化的原因。或者,链接器的行为与最新的工具链不同。我只能说这曾经有效,现在无效。
仅遵循这些准则是不够的:Cross-Platform and Native Applications
要解决此问题,首先确保在 iOS 项目、Android 和 .NET Standard 共享项目中都安装了 Autofac,然后选择以下两个选项之一:
- 将链接器设置为
Don't link
或 Link Framework SDK's Only
- 或者,你可以;将
--linkskip=Autofac
(区分大小写!)添加到 iOS 项目属性中 iOS Build
中的 Additional mtouch arguments
。
- 或者,你可以;创建一个 Custom Linker Configuration file,顺便说一下,如果您需要链接,我认为这是最好的选择。这需要做更多的工作,但是当使用
Linker Description file
时,编译器会在您构建时为您提供可用的反馈,如果您犯了拼写错误等错误。此外,Linker Description file
有一个Android 和 iOS. 格式相同
注意:选项 2 和 3 只会稍微增加您的应用程序大小,因为它将确保所有 Autofac 程序集都包含在您的应用程序包中,而所有其他未指定为 2 或 3 的一部分的程序集将继续链接。
我假设需要这些变通办法之一表明 Autofac 目前不是链接器安全的。
升级到 Visual Studio 16.3.0 后(Visual Studio for Mac 8.3.1805)Autofac 在以前工作的项目中执行 builder.Build()
时抛出异常:
The type 'Autofac.Features.Indexed.KeyedServiceIndex'2' does not implement the interface 'Autofac.Features.Indexed.IIndex'2'
对于 Visual Studio 的这个版本(可能还有更早的版本),iOS 是使用 Mono 6.4.0.198 编译的,我怀疑这可能是引入制动变化的原因。或者,链接器的行为与最新的工具链不同。我只能说这曾经有效,现在无效。
仅遵循这些准则是不够的:Cross-Platform and Native Applications
要解决此问题,首先确保在 iOS 项目、Android 和 .NET Standard 共享项目中都安装了 Autofac,然后选择以下两个选项之一:
- 将链接器设置为
Don't link
或Link Framework SDK's Only
- 或者,你可以;将
--linkskip=Autofac
(区分大小写!)添加到 iOS 项目属性中iOS Build
中的Additional mtouch arguments
。 - 或者,你可以;创建一个 Custom Linker Configuration file,顺便说一下,如果您需要链接,我认为这是最好的选择。这需要做更多的工作,但是当使用
Linker Description file
时,编译器会在您构建时为您提供可用的反馈,如果您犯了拼写错误等错误。此外,Linker Description file
有一个Android 和 iOS. 格式相同
注意:选项 2 和 3 只会稍微增加您的应用程序大小,因为它将确保所有 Autofac 程序集都包含在您的应用程序包中,而所有其他未指定为 2 或 3 的一部分的程序集将继续链接。
我假设需要这些变通办法之一表明 Autofac 目前不是链接器安全的。