首页 > 解决方案 > 简单的喷油器激活异常 Xamarin 表单。我无法浏览我的应用程序

问题描述

我在我的解决方案中使用了简单的 DI 注入器。xamarin 更新后它停止工作。我可以导航一次,然后它会抛出Activation Exception :此实例已经启动了一个或多个请求。只能在发送第一个请求之前修改属性。

这是我的 App.xaml.cs

public App(Container container) {
    this.container = container;

    InitializeComponent();

    this.InitConfig();
}

private void InitConfig() {
    //Setup Styles to be used on different controls
    SetupResources();

    //Data Bindings
    DataBindings();

    //Service Bindings
    ServiceBindings();

    //Business Bindings
    BusinessBindings();

    //ViewModels Bindings
    ViewModelsBindings();

    MainPage = new NavigationPage(
        container.GetInstance<ViewManager>()
        .Navigate<MainMenuViewModel>().View) {
        BarTextColor = Color.FromHex("#7A7B7C")
    };

> this navigate works

    container.GetInstance<PendingRequestSender>().Start();
}

ViewModels绑定:

protected void ViewModelsBindings() {
    container.Register<UIHelperService>(Lifestyle.Singleton);
    ViewManager viewManager = new ViewManager(container);
    container.RegisterSingleton(viewManager);
    viewManager.RegisterView<MainMenuView, MainMenuViewModel>();
    viewManager.RegisterView<AdjustInventoryView, AdjustInventoryViewModel>();
    viewManager.RegisterView<CustomerPickUpView, CustomerPickUpViewModel>();
    viewManager.RegisterView<CycleCountFullInventoryView, CycleCountFullInventoryViewModel>();
    viewManager.RegisterView<FinishReceiverView, FinishReceiverViewModel>();
    viewManager.RegisterView<FinishReceiverConfirmationView, FinishReceiverConfirmationViewModel>();
    viewManager.RegisterView<ProcessNotShipView, ProcessNotShipViewModel>();
}

视图管理器:

public class ViewManager {
    readonly Dictionary<Type, Type> modelToView;
    readonly Container container;

    public ViewManager(Container container) {
        this.container = container;
        modelToView = new Dictionary<Type, Type>();
    }

    public void RegisterView<V, M>() where V : Page where M : BaseViewModel {
        modelToView[typeof(M)] = typeof(V);
        container.Register<M>();
        container.Register<V>();
    }

    public ViewItem<Page, M> Navigate<M>() where M : BaseViewModel {
        M model = container.GetInstance<M>();
        Page view = (Page)container.GetInstance(modelToView[typeof(M)]);
        return new ViewItem<Page, M>(view, model);
    }
}

例如我想以这种方式导航:

void OnReceiveShipmentClicked() {
    userManager.RunAuthenticated(() => {
        viewManager.Navigate<ReceiveShipmentViewModel>()
           .Setup((model) => {
               model.pallets = _localPalletService.RetrievePalletList(userManager.ID());
           })
           .Go();
    },
     TxtEnvironment);
}

堆栈跟踪:

at SimpleInjector.InstanceProducer.BuildExpression () [0x0003d] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Advanced.DefaultDependencyInjectionBehavior.BuildExpression (SimpleInjector.InjectionConsumerInfo consumer) [0x00012] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.ContainerOptions.BuildParameterExpression (SimpleInjector.InjectionConsumerInfo consumer) [0x00006] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildConstructorParameterFor (SimpleInjector.InjectionConsumerInfo consumer) [0x00016] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildConstructorParameters (System.Type serviceType, System.Type implementationType, System.Reflection.ConstructorInfo constructor) [0x0001f] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildNewExpression (System.Type serviceType, System.Type implementationType) [0x0002c] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildTransientExpression[TService,TImplementation] () [0x00000] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Lifestyles.SingletonLifestyle+SingletonLifestyleRegistration`2[TService,TImplementation].BuildTransientExpression () [0x00000] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Lifestyles.SingletonLifestyle+SingletonLifestyleRegistrationBase`1[TService].CreateInstanceWithNullCheck () [0x00000] in <215303bfc4464c2fb19e1665117477b4>:0 
at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:333 
at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:351 
at System.Lazy`1[T].CreateValue () [0x00074] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:431 
at System.Lazy`1[T].get_Value () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:509 
at SimpleInjector.Lifestyles.SingletonLifestyle+SingletonLifestyleRegistrationBase`1[TService].BuildExpression () [0x00000] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildExpression (SimpleInjector.InstanceProducer producer) [0x00007] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.InstanceProducer.BuildExpressionInternal () [0x00011] in <215303bfc4464c2fb19e1665117477b4>:0 
at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:333 
at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:351 
at System.Lazy`1[T].CreateValue () [0x00074] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:431 
at System.Lazy`1[T].get_Value () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:509 
at SimpleInjector.InstanceProducer.BuildExpression () [0x0003e] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Advanced.DefaultDependencyInjectionBehavior.BuildExpression (SimpleInjector.InjectionConsumerInfo consumer) [0x00012] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.ContainerOptions.BuildParameterExpression (SimpleInjector.InjectionConsumerInfo consumer) [0x00006] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildConstructorParameterFor (SimpleInjector.InjectionConsumerInfo consumer) [0x00016] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildConstructorParameters (System.Type serviceType, System.Type implementationType, System.Reflection.ConstructorInfo constructor) [0x0001f] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildNewExpression (System.Type serviceType, System.Type implementationType) [0x0002c] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildTransientExpression[TService,TImplementation] () [0x00000] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Lifestyles.TransientLifestyle+TransientLifestyleRegistration`2[TService,TImplementation].BuildExpression () [0x00000] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Registration.BuildExpression (SimpleInjector.InstanceProducer producer) [0x00007] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.InstanceProducer.BuildExpressionInternal () [0x00011] in <215303bfc4464c2fb19e1665117477b4>:0 
at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:333 
at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:351 
at System.Lazy`1[T].CreateValue () [0x00074] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:431 
at System.Lazy`1[T].get_Value () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:509 
at SimpleInjector.InstanceProducer.BuildInstanceCreator () [0x00000] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.InstanceProducer.BuildAndReplaceInstanceCreatorAndCreateFirstInstance () [0x00000] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.InstanceProducer.GetInstance () [0x00052] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Container.GetInstanceFromProducer (SimpleInjector.InstanceProducer instanceProducer, System.Type serviceType) [0x0000a] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Container.GetInstanceForRootType[TService] () [0x0001d] in <215303bfc4464c2fb19e1665117477b4>:0 
at SimpleInjector.Container.GetInstance[TService] () [0x0001f] in <215303bfc4464c2fb19e1665117477b4>:0 
at Warehouse.UI.Manager.ViewManager.Navigate[M] () [0x00001] in /Users/aragonzalez/Projects/Warehouse/Warehouse/UI/Manager/ViewManager.cs:25 
at Warehouse.UI.ViewModels.MainMenuViewModel.<OnReceiveShipmentClicked>b__48_0 () [0x00001] in /Users/aragonzalez/Projects/Warehouse/Warehouse/UI/ViewModels/MainMenuViewModel.cs:216 
at Warehouse.Business.UserManager+<>c__DisplayClass6_0.<Warehouse.Business.IUserManager.RunAuthenticated>b__2 () [0x00001] in /Users/aragonzalez/Projects/Warehouse/Warehouse/Business/UserManager.cs:32 
at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.39/src/Xamarin.iOS/Foundation/NSAction.cs:152 
--- End of stack trace from previous location where exception was thrown ---

at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.39/src/Xamarin.iOS/UIKit/UIApplication.cs:86 
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.39/src/Xamarin.iOS/UIKit/UIApplication.cs:65 
at Warehouse.iOS.Application.Main (System.String[] args) [0x00001] in /Users/aragonzalez/Projects/Warehouse/iOS/Main.cs:15 

我不明白异常以及为什么它第一次起作用然后抛出异常。

标签: xamarinsimple-injector

解决方案


推荐阅读