我收到有关我们的实时环境中罕见且间歇性错误的报告.我尝试重现它并没有成功,错误本身就是一个小谜.除此之外,它似乎涉及企业库跟踪(我们使用的是5.0版本) - 总而言之,有点痛苦.这是在Windows Sever 2008上发生的,应用程序在.Net Framework 4.0(WPF)上.
错误消息和堆栈跟踪如下:
ArgumentNullException: Value cannot be null. Parameter name: category
<StackTrace>
Server stack trace:
at Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry.BuildCategoriesCollection(String category)
at Microsoft.Practices.EnterpriseLibrary.Logging.Tracer.WriteTraceMessage(String message, String entryTitle, TraceEventType eventType)
at Microsoft.Practices.EnterpriseLibrary.Logging.Tracer.WriteTraceEndMessage(String entryTitle)
at Microsoft.Practices.EnterpriseLibrary.Logging.Tracer.Dispose()
at TestApplication.ViewModelTest.<UpdateUsers>d__1a.MoveNext()
Exception rethrown at [0]:
at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.<SetException>b__1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
</StackTrace> …Run Code Online (Sandbox Code Playgroud) 我在 Shell.xaml 中有一个 TabControl 区域:
<TabControl Name="TabRegionControl" prism:RegionManager.RegionName="TabRegion" />
Run Code Online (Sandbox Code Playgroud)
用户可以单击按钮打开一个新选项卡,该选项卡调用:
RegionManager.RequestNavigate("TabRegion", new Uri("Search?X=1", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
新选项卡在选项卡控件中创建并显示视图。该视图包含多个子区域(以及每个区域的视图)。到目前为止,这有效。当用户再次单击该按钮时,我收到错误消息,指出区域已注册。
我知道这是因为这些区域无法在同一个区域管理器中再次注册。我读过可以使用作用域区域来解决这个问题。尽我所能,我用这个替换上面的 RequestNavigate 来创建一个有作用域的 RegionManager:
SearchViewModel svm = new SearchViewModel();
IRegion detailsRegion = _regionManager.Regions["TabRegion"];
SearchView view = new SearchView(svm);
IRegionManager scopedRegionManager = detailsRegion.Add(view, null, true);
svm.ScopedRegionManager = scopedRegionManager;
svm.LoadViews();
Run Code Online (Sandbox Code Playgroud)
我相信我必须在方法 LoadViews() 中手动将视图加载到我的子区域中,但是子区域没有显示。
以下是它们在 Search.xaml 中的定义方式:
<ContentControl Background="White" Grid.Row="0" Grid.Column="0"
Regions:RegionManager.RegionName="SubRegion1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch" />
Run Code Online (Sandbox Code Playgroud)
作为起点,scopedRegionManager 在它的区域集合中似乎没有我的任何子区域。
编辑
我现在看到范围区域管理器的区域集合中的子区域。子视图仍未显示,这是我尝试在 LoadViews 方法中加载子视图的方式,这可能完全偏离:
ViewModelSub1 vm = new ViewModelSub1();
IRegion detailsRegion = _regionManager.Regions["RegionSub1"];
SubView1 sView = new SubView1(vm);
IRegionManager …Run Code Online (Sandbox Code Playgroud)