Deep Link : User can not redirect in same browser by changing URL from Address bar, due to RegionCreationException occurred for wall module region.

Topics: Prism v2 - Silverlight 3
Nov 25, 2009 at 11:25 AM
Edited Nov 25, 2009 at 11:26 AM

Hello Every one,

I have implemented deep link using Prism V2.

My Issue is "User can not redirect in same browser by changing URL from Address bar, due to RegionCreationException occurred for wall module region."

. Exectly it is given error in  ContentControlRegionAdapter Class of Microsoft.Practices.Composite.Presentation.Regions project at protected override void Adapt(IRegion region, ContentControl regionTarget) method when it tries to set contect of TargetRegion.(Added method given below, it throws error at code bolded below.)

protected override void Adapt(IRegion region, ContentControl regionTarget)
        {
            bool contentIsSet = regionTarget.Content != null;
#if !SILVERLIGHT
            contentIsSet = contentIsSet || (BindingOperations.GetBinding(regionTarget, ContentControl.ContentProperty) != null);
#endif
            if (contentIsSet)
            {
                throw new InvalidOperationException(Resources.ContentControlHasContentException);
            }

            region.ActiveViews.CollectionChanged += delegate
            {
                regionTarget.Content = region.ActiveViews.FirstOrDefault();                
            };

            region.Views.CollectionChanged +=
                (sender, e) =>
                {
                    if (e.Action == NotifyCollectionChangedAction.Add && region.ActiveViews.Count() == 0)
                    {
                        region.Activate(e.NewItems[0]);
                    }
                };
        }

 

Error stack is given below....

{Microsoft.Practices.Composite.Presentation.Regions.Behaviors.RegionCreationException: An exception occurred while creating a region with name 'XyZRegion'.
The exception was: System.ArgumentException: Value does not fall within the expected range.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper doh, DependencyProperty property, Object obj)
   at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Controls.ContentControl.set_Content(Object value)
   at Microsoft.Practices.Composite.Presentation.Regions.ContentControlRegionAdapter.<>c__DisplayClass2.<Adapt>b__0(Object , NotifyCollectionChangedEventArgs )
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.AddAndNotify(IList items)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.AddAndNotify(Object item)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.itemMetadata_MetadataChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata.InvokeMetadataChanged()
   at Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata.DependencyPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata.set_IsActive(Boolean value)
   at Microsoft.Practices.Composite.Presentation.Regions.Region.Activate(Object view)
   at Microsoft.Practices.Composite.Presentation.Regions.SingleActiveRegion.Activate(Object view)
   at Microsoft.Practices.Composite.Presentation.Regions.ContentControlRegionAdapter.<>c__DisplayClass2.<Adapt>b__1(Object sender, NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.AddAndNotify(IList items)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.UnderlyingCollection_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at Microsoft.Practices.Composite.Presentation.Regions.Region.InnerAdd(Object view, String viewName, IRegionManager scopedRegionManager)
   at Microsoft.Practices.Composite.Presentation.Regions.Region.Add(Object view, String viewName, Boolean createRegionManagerScope)
   at Microsoft.Practices.Composite.Presentation.Regions.Region.Add(Object view)
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.AutoPopulateRegionBehavior.AddViewIntoRegion(Object viewToAdd)
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.AutoPopulateRegionBehavior.StartPopulatingContent()
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.AutoPopulateRegionBehavior.OnAttach()
   at Microsoft.Practices.Composite.Presentation.Regions.RegionBehavior.Attach()
   at Microsoft.Practices.Composite.Presentation.Regions.RegionBehaviorCollection.Add(String key, IRegionBehavior regionBehavior)
   at Microsoft.Practices.Composite.Presentation.Regions.RegionAdapterBase`1.AttachDefaultBehaviors(IRegion region, T regionTarget)
   at Microsoft.Practices.Composite.Presentation.Regions.RegionAdapterBase`1.Initialize(T regionTarget, String regionName)
   at Microsoft.Practices.Composite.Presentation.Regions.RegionAdapterBase`1.Microsoft.Practices.Composite.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName).  ---> System.ArgumentException: Value does not fall within the expected range.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper doh, DependencyProperty property, Object obj)
   at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Controls.ContentControl.set_Content(Object value)
   at Microsoft.Practices.Composite.Presentation.Regions.ContentControlRegionAdapter.<>c__DisplayClass2.<Adapt>b__0(Object , NotifyCollectionChangedEventArgs )
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.AddAndNotify(IList items)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.AddAndNotify(Object item)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.itemMetadata_MetadataChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata.InvokeMetadataChanged()
   at Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata.DependencyPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata.set_IsActive(Boolean value)
   at Microsoft.Practices.Composite.Presentation.Regions.Region.Activate(Object view)
   at Microsoft.Practices.Composite.Presentation.Regions.SingleActiveRegion.Activate(Object view)
   at Microsoft.Practices.Composite.Presentation.Regions.ContentControlRegionAdapter.<>c__DisplayClass2.<Adapt>b__1(Object sender, NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.AddAndNotify(IList items)
   at Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.UnderlyingCollection_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at Microsoft.Practices.Composite.Presentation.Regions.Region.InnerAdd(Object view, String viewName, IRegionManager scopedRegionManager)
   at Microsoft.Practices.Composite.Presentation.Regions.Region.Add(Object view, String viewName, Boolean createRegionManagerScope)
   at Microsoft.Practices.Composite.Presentation.Regions.Region.Add(Object view)
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.AutoPopulateRegionBehavior.AddViewIntoRegion(Object viewToAdd)
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.AutoPopulateRegionBehavior.StartPopulatingContent()
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.AutoPopulateRegionBehavior.OnAttach()
   at Microsoft.Practices.Composite.Presentation.Regions.RegionBehavior.Attach()
   at Microsoft.Practices.Composite.Presentation.Regions.RegionBehaviorCollection.Add(String key, IRegionBehavior regionBehavior)
   at Microsoft.Practices.Composite.Presentation.Regions.RegionAdapterBase`1.AttachDefaultBehaviors(IRegion region, T regionTarget)
   at Microsoft.Practices.Composite.Presentation.Regions.RegionAdapterBase`1.Initialize(T regionTarget, String regionName)
   at Microsoft.Practices.Composite.Presentation.Regions.RegionAdapterBase`1.Microsoft.Practices.Composite.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
   --- End of inner exception stack trace ---
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.DelayedRegionCreationBehavior.TryCreateRegion()
   at Microsoft.Practices.Composite.Presentation.Regions.Behaviors.DelayedRegionCreationBehavior.ElementLoaded(Object sender, RoutedEventArgs e)
   at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

 

If any one has any idea on same then please let me know as I need to solve this at urgent bases.

 

Thanks

Regards

DJ

Nov 25, 2009 at 2:33 PM
Edited Nov 25, 2009 at 2:34 PM

Hi DJ,

Silverlight 3 Navigation cannot be fully leveraged with Prism-v2 if you are loading modules remotely. You can read about the cause of this here. However, as I do not know if this is the case for your application I cannot tell if it is related to your issue.

It might be useful if you could provide a repro sample so we can try to find a workaround for it.

Please let me know if this helps.

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

Nov 26, 2009 at 2:36 PM

Hello Damian Schenkelman

Thanks for your reply, but I just want to implement deep link in static module loading.

After debugging code I came to know that it is due to the container.RegisterType

When I am write container.RegisterType<"Interface" , "Implementation">(); It will not show me proper view,

When I am write container.RegisterType<"Interface" , "Implementation">(new ContainerControlledLifetimeManager()); It will load desire view but it give error given above.

I think issue is due to region and view registration.

I have register region using regionManager.RegisterViewWithRegion rather then Add view into the region as in navigation I does not get region in region manager as my region declaration is not in shell but in other xaml.

Is there any other way to add region in to the region manager so ?

Regards

DJ

 

 

 

Nov 27, 2009 at 7:33 PM

Hi DJ,

The difference between how you are doing the type registrations is that when using the LifetimeManager “Unity returns the same instance of the registered type or object each time you call the Resolve or ResolveAll method or when the dependency mechanism injects instances into other classes”. (from the Unity documentation). If you do not used this approach (you do it the first way) you will get a new instance when you call the Resolve method.

As for how to register views, you can read about that here:

You can also check the following Quickstarts and also the RI (that are located where you decompressed Prism), which show different ways of registering views:

You might find this blog post by Mariano Converti interesting. He provides a way to do navigation with Prism-v2 and static module loading.

If you still have this issue, please provide a repro sample so we can try to reproduce it and provide a fix for it.

Please let me know if this helps.

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