C# Autofac依赖项注入在调试时工作,但在发布时崩溃

C# Autofac依赖项注入在调试时工作,但在发布时崩溃,c#,dependency-injection,xamarin,autofac,C#,Dependency Injection,Xamarin,Autofac,当我的DI在调试模式下正常时,什么会导致它在发布模式下崩溃?这是一个Xamarin.Forms应用程序,正在Android上运行 07-23 20:56:53.002 I/MonoDroid(15451): UNHANDLED EXCEPTION: Autofac.Core.DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerExcepti

当我的DI在调试模式下正常时,什么会导致它在发布模式下崩溃?这是一个Xamarin.Forms应用程序,正在Android上运行

07-23 20:56:53.002 I/MonoDroid(15451): UNHANDLED EXCEPTION: Autofac.Core.DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> Object reference not set to an instance of an object (See inner exception for details.) ---> System.NullReferenceException: Object reference not set to an instance of an object
07-23 20:56:53.002 I/MonoDroid(15451):   at System.Linq.Expressions.Expression.CreateLambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, System.Collections.ObjectModel.ReadOnlyCollection`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Features.GeneratedFactories.FactoryGenerator.CreateGenerator (System.Func`3 makeResolveCall, System.Type delegateType, ParameterMapping pm) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Features.GeneratedFactories.FactoryGenerator..ctor (System.Type delegateType, IComponentRegistration productRegistration, ParameterMapping parameterMapping) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Features.GeneratedFactories.GeneratedFactoryRegistrationSource+<>c__DisplayClass2.<RegistrationsFor>b__0 (IComponentRegistration r) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[Autofac.Core.IComponentRegistration,Autofac.Core.IComponentRegistration].MoveNext () [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Registration.ComponentRegistry.GetInitializedServiceInfo (Autofac.Core.Service service) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Registration.ComponentRegistry.TryGetRegistration (Autofac.Core.Service service, IComponentRegistration& registration) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Activators.Reflection.AutowiringParameter.CanSupplyValue (System.Reflection.ParameterInfo pi, IComponentContext context, System.Func`1& valueProvider) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Activators.Reflection.ConstructorParameterBinding..ctor (System.Reflection.ConstructorInfo ci, IEnumerable`1 availableParameters, IComponentContext context) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Activators.Reflection.ReflectionActivator+<>c__DisplayClass5.<GetConstructorBindings>b__4 (System.Reflection.ConstructorInfo ci) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[System.Reflection.ConstructorInfo,Autofac.Core.Activators.Reflection.ConstructorParameterBinding].MoveNext () [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1E`1[Autofac.Core.Activators.Reflection.ConstructorParameterBinding].MoveNext () [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at System.Linq.Enumerable.ToArray[ConstructorParameterBinding] (IEnumerable`1 source) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance (IComponentContext context, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Resolving.InstanceLookup.Activate (IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Resolving.InstanceLookup.Execute () [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance (ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Resolving.ResolveOperation.ResolveComponent (IComponentRegistration registration, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   at Autofac.Core.Resolving.ResolveOperation.Execute (IComponentRegistration registration, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:53.002 I/MonoDroid(15451):   -
Unhandled Exception:

Autofac.Core.DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> Object reference not set to an instance of an object (See inner exception for details.)

07-23 20:56:54.003 E/mono    (15451): 
07-23 20:56:54.003 E/mono    (15451): Unhandled Exception:
07-23 20:56:54.003 E/mono    (15451): Autofac.Core.DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> Object reference not set to an instance of an object (See inner exception for details.) ---> System.NullReferenceException: Object reference not set to an instance of an object
In mgmain JNI_OnLoad
07-23 20:56:54.003 E/mono    (15451):   at System.Linq.Expressions.Expression.CreateLambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, System.Collections.ObjectModel.ReadOnlyCollection`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:54.003 E/mono    (15451):   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:54.003 E/mono    (15451):   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:54.003 E/mono    (15451):   at Autofac.Features.Generate
07-23 20:56:54.003 E/mono-rt (15451): [ERROR] FATAL UNHANDLED EXCEPTION: Autofac.Core.DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> Object reference not set to an instance of an object (See inner exception for details.) ---> System.NullReferenceException: Object reference not set to an instance of an object
07-23 20:56:54.003 E/mono-rt (15451):   at System.Linq.Expressions.Expression.CreateLambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, System.Collections.ObjectModel.ReadOnlyCollection`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:54.003 E/mono-rt (15451):   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:54.003 E/mono-rt (15451):   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
07-23 20:56:54.003 E/mono-rt (15451):   at Autofac.Feat
The program 'Mono' has exited with code 0 (0x0).
07-23 20:56:53.002 I/MonoDroid(15451):未处理的异常:Autofac.Core.DependencyResolutionException:执行解析操作时引发异常。有关详细信息,请参阅InnerException。-->对象引用未设置为对象的实例(有关详细信息,请参见内部异常)。-->System.NullReferenceException:对象引用未设置为对象的实例
07-23 20:56:53.002 I/MonoDroid(15451):位于System.Linq.Expressions.Expression.CreateLambda(System.Type delegateType,System.Linq.Expressions.Expression正文,System.String名称,布尔尾调用,System.Collections.ObjectModel.ReadOnlyCollection`1参数)[0x00000 in:0
07-23 20:56:53.002 I/MonoDroid(15451):位于System.Linq.Expressions.Expression.Lambda(System.Type delegateType,System.Linq.Expressions.Expression主体,System.String名称,布尔尾调用,IEnumerable`1参数)[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在System.Linq.Expressions.Expression.Lambda(System.Type delegateType,System.Linq.Expressions.Expression body,IEnumerable`1参数)[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Features.GeneratedFactorys.FactoryGenerator.CreateGenerator(System.Func`3 makeResolveCall,System.Type delegateType,ParameterMapping pm)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Features.GeneratedFactorys.FactoryGenerator.ctor(System.Type delegateType,IComponentRegistration productRegistration,ParameterMapping ParameterMapping)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Features.GeneratedFactories.GeneratedFactories.GeneratedFactoryRegistrationSource+c_uu显示Class2.b_u0(IComponentRegistration r)[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在System.Linq.Enumerable+c_u迭代器10`2[Autofac.Core.IComponentRegistration,Autofac.Core.IComponentRegistration].MoveNext()[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Registration.ComponentRegistry.GetInitializedServiceInfo(Autofac.Core.Service服务)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Registration.ComponentRegistry.TryGetRegistration(Autofac.Core.Service服务,IComponentRegistration&Registration)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):位于Autofac.Core.Activators.Reflection.AutowiringParameter.CanSupplyValue(System.Reflection.ParameterInfo pi,IComponentContext,System.Func`1和valueProvider)[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Activators.Reflection.ConstructorParameterBinding.ctor(System.Reflection.ConstructorInfo ci,IEnumerable`1 availableParameters,IComponentContext上下文)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Activators.Reflection.ReflectionActivator+c__DisplayClass5.b__4(System.Reflection.ConstructorInfo ci)[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在System.Linq.Enumerable+c_uu迭代器10`2[System.Reflection.ConstructorInfo,Autofac.Core.Activators.Reflection.ConstructorParameterBinding].MoveNext()[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在System.Linq.Enumerable+c__迭代器1E`1[Autofac.Core.Activators.Reflection.ConstructorParameterBinding].MoveNext()[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在System.Linq.Enumerable.ToArray[ConstructorParameterBinding](IEnumerable`1源)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext,IEnumerable`1参数)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1参数)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):位于Autofac.Core.Resolving.InstanceLookup.Execute()[0x00000]in:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Resolving.resolvecooperation.GetOrCreateInstance(iShareInfetimescope currentOperationScope,IComponentRegistration,IEnumerable`1参数)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Resolving.resolvecooperation.ResolveComponent(IComponentRegistration,IEnumerable`1参数)[0x00000]中:0
07-23 20:56:53.002 I/MonoDroid(15451):在Autofac.Core.Resolving.resolvecooperation.Execute(IComponentRegistration,IEnumerable`1参数)[0x00000]中:0
07-23 20:56:53.002 I/单机器人(15451):-
未处理的异常:
Autofac.Core.DependencyResolutionException:执行解析操作时引发异常。有关详细信息,请参阅InnerException。-->对象引用未设置为对象的实例(有关详细信息,请参见内部异常)
07-23 20:56:54.003 E/mono(15451):
07-23 20:56:54.003 E/mono(15451):未处理的异常:
07-23 20:56:54.003 E/mono(15451):Autofac.Core.dependencResolutionException:执行解析操作时引发异常。有关详细信息,请参阅InnerException。-->对象引用未设置为对象的实例(有关详细信息,请参见内部异常)。-->System.NullReferenceException:对象引用未设置为对象的实例
在mgmain JNI_OnLoad中
07-23 20:56:54.003 E/mono(15451):在System.Linq.Expressions.Expression.CreateLambda(System.Type delegateType,System.Linq.Expressions.Expression.Expression正文,System.String名称,布尔尾调用,System.Collections.ObjectModel.ReadOnlyCollection`1参数)[0x00000 in:0
07-23 20:56:54.003 E/mono(15451):at System.Linq.Expressions.Expression.Lambda(System.Type delegateType,System.Linq.Expressions.Expression body,System.String name,Boolean tailCall,IEnumerable`1参数)[0x00000]in:0
07-23 20:56:54.003 E/mono(15451):at System.Linq.Expressio
    public MainPage(Func<Action, Action<bool?>, MainMenu> mainMenu, 
                    ModulePage modulePage, 
                    LoadingPage loadingPage, 
                    Func<Action, AuthPage> authPage,
                    IUserDialogService userDialogService, 
                    IModuleService moduleService, 
                    ISyncCommand syncCommand)
    {
        _loadingPage = loadingPage;
        _authPage = authPage;
        _userDialogService = userDialogService;
        _moduleService = moduleService;
        _syncCommand = syncCommand;

        Title = Strings.app_title;
        var master = mainMenu(OnAfterDeauthenticated, OnToggleRequest());
        var detail = new NavigationPage(modulePage);

        if (App.Navigation == null)
        {
            App.Navigation = detail.Navigation;
        }

        Master = master;
        Detail = detail;
    }
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        Forms.Init(this, bundle);

        var container = RegisterDependencies();
        var page = App.GetMainPage(container);

        SetPage(page);
    }

    private static IContainer RegisterDependencies()
    {
        var containerBuilder = new ContainerBuilder();
        RegisterAndroidSpecific(containerBuilder);

        var coreIoc = new CoreIoC(containerBuilder);
        return coreIoc.Load();
    }

    private static void RegisterAndroidSpecific(ContainerBuilder containerBuilder)
    {
        containerBuilder.RegisterType<AudioPlayer>().SingleInstance().As<IAudioPlayer>();
        containerBuilder.RegisterType<SettingsService>().As<ISettingsService>();
        containerBuilder.RegisterType<NetworkService>().As<INetworkService>();
        containerBuilder.RegisterType<NativeVideoPlayer>().As<IVideoPlayer>();
        containerBuilder.RegisterType<MarkdownService>().As<IMarkdownService>();
        containerBuilder.RegisterType<UserDialogService>().As<IUserDialogService>();

        containerBuilder.RegisterType<DbProvider>()
            .SingleInstance()
            .WithParameters(new List<Parameter> {
                new TypedParameter(typeof(string), "fsm-breathingroom"),
                new TypedParameter(typeof(SqliteSettings), new SqliteSettings {
                    CacheSize = 16777216,
                    SyncMode = SynchronizationModes.Off,
                    JournalMode = SQLiteJournalModeEnum.Off,
                    PageSize = 65536
                })
            })
            .As<IDbProvider>();
    }
    public static Page GetMainPage(IContainer container)
    {
        Container = container;

        RegisterCurrentUser(Container.Resolve<UserModel>());
        RunMigrations();
        RegisterCurrentUser();

        var rootPage = Container.Resolve<MainPage>();
        return rootPage;
    }
private FooPageFactory _fooPage
public SomePage(FooPageFactory fooPage)
{
    _fooPage = fooPage;
    // when needed
    _fooPage.Init(SomeActionDependency);
}
builder.Register<Func<FooPage>>(c => () => new FooPage());