首页 > 解决方案 > Xamarin Android 应用程序中的 Autofac 错误

问题描述

我在 Xamarin 项目中使用 Autofac 来构建移动应用程序。在 Xamarin Live Player 1.5.176 (676) 中构建 Autofac 容器时出现以下错误(在华为 P20 上,最后一个安全补丁):

[LogEntry:时间=01/07/2018 11:00:08 +02:00,级别=错误,标题=可视化错误,消息=方法 System.Collections.Generic.IEnumerable 1<Autofac.Core.IComponentRegistration> Autofac.Core.IRegistrationSource::RegistrationsFor(Autofac.Core.Service,System.Func2>) 上没有正文 (NInterpretException)]

我提出了重现该问题的解决方案:https ://github.com/EhRom/XamarinAutofac/

// Initialiaze container builder.
var containerBuilder = new ContainerBuilder();

containerBuilder.RegisterType<SampleViewModel>().As<ISampleViewModel>();

// Build container.
container = containerBuilder.Build();

错误发生在 Build() 方法上。我尝试添加选项,但没有成功。

你有没有遇到过这个问题?我该如何解决这个问题?

该错误不会在本地模拟器上重现(没有 Xamarin Live Player)。

标签: xamarin.androidautofac

解决方案


问题来自 Xamarin Live Player。

我直接在我的手机上部署了 apk 并且工作正常。


推荐阅读