Event Subscription Error

Topics: Prism v2 - Silverlight 3
Apr 23, 2010 at 2:32 AM

hey all,

Im working with Prism v2, SL4

Im try to subscribe to an in one module that I publish from another. The publish part goes fine but when I try to subscribe, I get the following error:

 

{Microsoft.Practices.Composite.Presentation.Regions.ViewRegistrationException: An exception has occurred while trying to add a view to region 'MovieDetailRegion'.     - The most likely causing exception was was: 'System.MethodAccessException: Attempt by method 'Microsoft.Practices.Composite.Events.DelegateReference.TryGetDelegate()' to access method 'NetflixMovieDetailUI.ViewModels.MovieDetailViewModel.OnMovieSelectedEvent(System.Object)' failed.   at System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType 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, ThreadOption threadOption)   at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent`1.Subscribe(Action`1 action)   at NetflixMovieDetailUI.ViewModels.MovieDetailViewModel..ctor(IEventAggregator eventAggregator)   at BuildUp_NetflixMovieDetailUI.ViewModels.MovieDetailViewModel(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)'.    But also check the InnerExceptions for more detail or call .GetRootException().  ---> Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type MovieDetailView, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "NetflixMovieDetailUI.Views.MovieDetailView", name = "". Exception message is: The current build operation (build key Build Key[NetflixMovieDetailUI.Views.MovieDetailView, null]) failed: The parameter model could not be resolved when attempting to call constructor NetflixMovieDetailUI.Views.MovieDetailView(NetflixMovieDetailUI.ViewModels.MovieDetailViewModel model). (Strategy type BuildPlanStrategy, index 3) ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[NetflixMovieDetailUI.Views.MovieDetailView, null]) failed: The parameter model could not be resolved when attempting to call constructor NetflixMovieDetailUI.Views.MovieDetailView(NetflixMovieDetailUI.ViewModels.MovieDetailViewModel model). (Strategy type BuildPlanStrategy, index 3) ---> System.InvalidOperationException: The parameter model could not be resolved when attempting to call constructor NetflixMovieDetailUI.Views.MovieDetailView(NetflixMovieDetailUI.ViewModels.MovieDetailViewModel model). ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[NetflixMovieDetailUI.ViewModels.MovieDetailViewModel, null]) failed: Attempt by method 'Microsoft.Practices.Composite.Events.DelegateReference.TryGetDelegate()' to access method 'NetflixMovieDetailUI.ViewModels.MovieDetailViewModel.OnMovieSelectedEvent(System.Object)' failed. (Strategy type BuildPlanStrategy, index 3) ---> System.MethodAccessException: Attempt by method 'Microsoft.Practices.Composite.Events.DelegateReference.TryGetDelegate()' to access method 'NetflixMovieDetailUI.ViewModels.MovieDetailViewModel.OnMovieSelectedEvent(System.Object)' failed.   at System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType 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, ThreadOption threadOption)   at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent`1.Subscribe(Action`1 action)   at NetflixMovieDetailUI.ViewModels.MovieDetailViewModel..ctor(IEventAggregator eventAggregator)   at BuildUp_NetflixMovieDetailUI.ViewModels.MovieDetailViewModel(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)   --- End of inner exception stack trace ---   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)   at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context)   at BuildUp_NetflixMovieDetailUI.Views.MovieDetailView(IBuilderContext )   --- End of inner exception stack trace ---   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context)   at BuildUp_NetflixMovieDetailUI.Views.MovieDetailView(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)   --- End of inner exception stack trace ---   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)   at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing)   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)   --- End of inner exception stack trace ---   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name)   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name)   at Microsoft.Practices.Composite.UnityExtensions.UnityServiceLocatorAdapter.DoGetInstance(Type serviceType, String key)   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)   --- End of inner exception stack trace ---   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType)   at Microsoft.Practices.Composite.Presentation.Regions.RegionViewRegistry.CreateInstance(Type type)   at Microsoft.Practices.Composite.Presentation.Regions.RegionViewRegistry.<>c__DisplayClass1.<RegisterViewWithRegion>b__0()   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.AutoPopulateRegionBehavior.OnViewRegistered(Object sender, ViewRegisteredEventArgs e)   --- End of inner exception stack trace ---   at Microsoft.Practices.Composite.Presentation.Regions.RegionViewRegistry.OnContentRegistered(ViewRegisteredEventArgs e)   at Microsoft.Practices.Composite.Presentation.Regions.RegionViewRegistry.RegisterViewWithRegion(String regionName, Func`1 getContentDelegate)   at Microsoft.Practices.Composite.Presentation.Regions.RegionViewRegistry.RegisterViewWithRegion(String regionName, Type viewType)   at Microsoft.Practices.Composite.Regions.RegionManagerExtensions.RegisterViewWithRegion(IRegionManager regionManager, String regionName, Type viewType)   at NetflixMovieDetailUI.Modules.Module.Initialize()   at Microsoft.Practices.Composite.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)}

 

when I remove the evt.Subscribe() it works just fine.

any thoughts would be greatly appreciated.

Thanks

Alex

 

Apr 23, 2010 at 3:39 PM

Hi Alex,

As you are using Silverlight, this exception is likely related to this issue.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman