我收到了关于我们的实时环境中出现罕见的间歇性错误的报告。我尝试重现它但没有成功,错误本身有点神秘。除此之外,它似乎涉及企业库跟踪(我们使用的是 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>
任何人都可以阐明可能导致此问题的原因吗?
编辑: 我没有修改 LogEntry.BuildCategoriesCollection。方法 BuildCategoriesCollection(String category) 的输入为空。
UpdateUsers方法如下:
async void UpdateUsers()
{
Processing = true;
using (traceMgr.StartTrace("Trace"))
using (var engine = new EngineClient())
{
Users = new List<UserMasterDataModel> { _blankUser };
var users = await engine.GetPossibleTagsTask(SelectedOutcomeId, _queue.SystemCd, _queue.QueueCd);
Users.AddRange(users);
}
if (SelectedUser != _blankUser)
{
// If null user selected then initialize to the case's tag, otherwise try to find the previously selected UserName
var userNameToFind = SelectedUser == null ? _details.TagTo : SelectedUser.UserName;
SelectedUser = Users.FirstOrDefault(user => user.UserName == userNameToFind) ?? _blankUser;
OnPropertyChanged("SelectedUser");
}
}
最佳答案
这个问题似乎也是 E-Lib 在以前版本中的一个已知错误。
已知为:从多个线程使用日志记录 AB 时出现未处理的异常。
“根本问题是,在 .NET 2.0 RTM 中,父线程的操作堆栈与其子线程共享,如果在创建子线程时存在这样的堆栈。”
在这里阅读更多: http://entlib.codeplex.com/workitem/9592
很难对此提出通用的解决方案,因为它在很大程度上取决于您应用的架构。
关于c# - 企业库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13016383/