我有一個我在View模型中訂閱的事件。事件訂閱是在通過統一創建的視圖模型的構造函數中完成的。使用棱鏡給予方法訪問異常的事件訂閱
我發現什麼,如果我的訂閱:
showViewAEvent.Subscribe(ShowViewAHasBeenRequested)或showViewAEvent.Subscribe(ShowViewAHasBeenRequested,假)我得到以下錯誤:
// {System.MethodAccessException: ModuleA.Views.ModuleAViewModel.ShowViewAHasBeenRequested(Boolean)
//at System.Delegate.BindToMethodInfo(Object target, RuntimeMethodHandle method, RuntimeTypeHandle methodType, DelegateBindingFlags flags)
//at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
//at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
//at Microsoft.Practices.Composite.Events.DelegateReference.TryGetDelegate()
//at Microsoft.Practices.Composite.Events.DelegateReference.get_Target()
//at Microsoft.Practices.Composite.Events.EventSubscription`1..ctor(IDelegateReference actionReference, IDelegateReference filterReference)
//at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent`1.Subscribe(Action`1 action, ThreadOption threadOption, Boolean keepSubscriberReferenceAlive, Predicate`1 filter)
//at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent`1.Subscribe(Action`1 action, ThreadOption threadOption, Boolean keepSubscriberReferenceAlive)
//at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent`1.Subscribe(Action`1 action, Boolean keepSubscriberReferenceAlive)
//at ModuleA.Views.ModuleAViewModel..ctor(IEventAggregator eventAggregator, IRegionManager regionManager)
//at BuildUp_ModuleA.Views.ModuleAViewModel(IBuilderContext)
//at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
//at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
//at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)}
但是,如果我設置該事件訂閱標誌爲true,我沒有得到錯誤。
由於我是棱鏡新手,如果我在正確的位置創建訂閱,我仍然試圖解決這個問題。 JDD。
JD。
我在堆棧跟蹤中找到訂閱方法後編輯了我的答案。我之前的回答假設你的應用程序稍後發生了一些事情。 –
請顯示您致電Subscribe的完整代碼,以及您通過的方法。 –