Prism IRegionManager updateregion is throwing IndexOutOfRangeEception.

K C, Soniya 21 Reputation points
2021-06-10T10:24:14.397+00:00

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.List1.RemoveAll(Predicate1 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.

Developer technologies | Windows Presentation Foundation
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.