question

KCSoniya-9882 avatar image
0 Votes"
KCSoniya-9882 asked KCSoniya-9882 commented

Prism IRegionManager updateregion is throwing IndexOutOfRangeEception.

Below exception is seen from framework side sporadically when we tried accessing RegionManager.Regions["FullScreen"].

In general if the region is not created/deactivated/removed either nullException or KeyNotFound exception should be thrown.

Here is the code : (crashed at if check)
if (this.myRegionManager.Regions["FullScreen"] == null)
{
//Log error to a file
}

Exception details:

       - Unhandled exception:

Sender: Name: MyProject.exe
There are no context policies.
Runtime Terminating: True
App.FailOnThreadException: True
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Array.Clear(Array array, Int32 index, Int32 length)
at System.Collections.Generic.List`1.RemoveAll(Predicate`1 match)
at Prism.Events.WeakDelegatesManager.Raise(Object[] args)
at Prism.Regions.RegionManager.UpdateRegions()
at Prism.Regions.RegionManager.RegionCollection.get_Item(String regionName)
at MyProject.Tool.<ViewData>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Please let us why there is exception and how to avoid it.

windows-wpf
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KCSoniya-9882
The IndexOutOfRangeEception that is thrown when an attempt is made to access an element of an array or collection with an index that is outside its bounds. But I can't analyze the reason for the error based on the code you provided. Did you add the region named FullScreen to myRegionManager? Please provide me enough code to make a sample to reproduce your error.


0 Votes 0 ·

Regions variable cannot be set by any client application its internal to PRISM not sure why IndexofRange is thrown.
If Regions is empty by any chance as per documentation(I have tested) KeyNotFound exception would be thrown.

Here is the code snippet :

void ViewData()
{
if (this.mRegionManager.Regions[mRegions.FullScreen] == null)
{
Trace.Error(myTraceDomain, string.Format(CultureInfo.InvariantCulture, "Region name {0} does not exist", mRegions.FullScreen));
return;
}

if (this.mView == null)
{
this.mView = new OverviewView(new OverviewViewModel(this.mModel));
this.mRegionManager.AddToRegion(mRegions.FullScreen, this.mView);
this.mView.Focusable = true;
}
}




0 Votes 0 ·

0 Answers