NullReferenceException in DelayedRegionCreationBehavior

Topics: Prism v4 - WPF 4
Aug 12, 2013 at 8:00 PM
I have ran into an issue and I'm having troubles troubleshooting. I am using Prism and have created a CustomDialogService which will add a view to a dialogRegion dynamically through code.

In the shell I have a dialogRegion defined with an explicit name. I've verified that everywhere in xaml the regions have a regionName that isn't null or empty. When I add a view into the region I am providing a name (unique name via guid.NewGuid().ToString) each time.

My question is this... based on the below exception, how can I verify/validate which Region has a RegionName coming back null and what is the DelayedRegionCreationBehavior doing?

I would pre-emptively create this region if I knew what region its blowing up on.

Thanks for any debugging/troubleshooting tips:

-Daniel

When I call the dialog service I get an error on DelayedRegionCreationBehavior:

{"An exception occurred while trying to create region objects.
- The most likely causing exception was: 'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Practices.Prism.Regions.Behaviors.RegionCreationException: An exception occurred while creating a region with name ''. The exception was: System.ArgumentNullException: Value cannot be null.
Parameter name: regionName
at Microsoft.Practices.Prism.Regions.RegionAdapterBase1.Initialize(T regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.RegionAdapterBase
1.Microsoft.Practices.Prism.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName). ---> System.ArgumentNullException: Value cannot be null.
Parameter name: regionName
at Microsoft.Practices.Prism.Regions.RegionAdapterBase1.Initialize(T regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.RegionAdapterBase
1.Microsoft.Practices.Prism.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
--- End of inner exception stack trace ---
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.TryCreateRegion()
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.OnUpdatingRegions(Object sender, EventArgs e)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at Microsoft.Practices.Prism.Events.WeakDelegatesManager.Raise(Object[] args)
at Microsoft.Practices.Prism.Regions.RegionManager.UpdateRegions()'.
But also check the InnerExceptions for more detail or call .GetRootException(). "}
Inner Exception -->

{"An exception occurred while creating a region with name ''. The exception was: System.ArgumentNullException: Value cannot be null.
Parameter name: regionName
at Microsoft.Practices.Prism.Regions.RegionAdapterBase1.Initialize(T regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.RegionAdapterBase
1.Microsoft.Practices.Prism.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName). "}

Inner Exception -->

{"Value cannot be null.
Parameter name: regionName"}
Aug 13, 2013 at 3:53 PM
Hi,

As far as I know, in order to validate/verify which Region has a null name, you will need to debug your solution along with the Prism Library. In order to do that, you will need to:

  • Remove any reference to Prism Library assemblies in your solution
  • Add the Prism Library projects to your solution
In addition, it would be helpful if you can provide us more information or even a code snippet of how you are defining your regions in XAML.

Regards,

Federico Martinez
http://blogs.southworks.net/fmartinez
Apr 16, 2014 at 6:27 AM
Hi ran up with same issue.

If I keep my application running for long time, say whole night and keep my PC locked. when i switch tabs of perform any interaction with application, It crashes and I get following error in Event logs.

ApplicationNeedsToClose The exception is: Microsoft.Practices.Prism.Regions.UpdateRegionsException: An exception occurred while trying to create region objects.
The most likely causing exception was: 'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Practices.Prism.Regions.Behaviors.RegionCreationException: An exception occurred while creating a region with name ''. The exception was: System.ArgumentNullException: Value cannot be null.
Parameter name: regionName
at Microsoft.Practices.Prism.Regions.RegionAdapterBase1.Initialize(T regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.RegionAdapterBase
1.Microsoft.Practices.Prism.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName). ---> System.ArgumentNullException: Value cannot be null.
Parameter name: regionName
at Microsoft.Practices.Prism.Regions.RegionAdapterBase1.Initialize(T regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.RegionAdapterBase
1.Microsoft.Practices.Prism.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
--- End of inner exception stack trace ---
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.TryCreateRegion()
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.OnUpdatingRegions(Object sender, EventArgs e)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at Microsoft.Practices.Prism.Events.WeakDelegatesManager.Raise(Object[] args)
at Microsoft.Practices.Prism.Regions.RegionManager.UpdateRegions()'.
But also check the InnerExceptions for more detail or call .GetRootException().  ---> Microsoft.Practices.Prism.Regions.Behaviors.RegionCreationException: An exception occurred while creating a region with name ''. The exception was: System.ArgumentNullException: Value cannot be null.
Parameter name: regionName
at Microsoft.Practices.Prism.Regions.RegionAdapterBase1.Initialize(T regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.RegionAdapterBase
1.Microsoft.Practices.Prism.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName). ---> System.ArgumentNullException: Value cannot be null.
Parameter name: regionName
at Microsoft.Practices.Prism.Regions.RegionAdapterBase1.Initialize(T regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.RegionAdapterBase
1.Microsoft.Practices.Prism.Regions.IRegionAdapter.Initialize(Object regionTarget, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
--- End of inner exception stack trace ---
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.TryCreateRegion()
at Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior.OnUpdatingRegions(Object sender, EventArgs e)
--- End of inner exception stack trace ---
at Microsoft.Practices.Prism.Regions.RegionManager.UpdateRegions()
at Microsoft.Practices.Prism.Regions.RegionManager.RegionCollection.ContainsRegionWithName(String regionName)