企业库错误

7
我收到了我们实时环境中一个罕见且间歇性的错误报告。我尝试复现此错误,但未能成功,而该错误本身也有点神秘。同时,似乎涉及Enterprise Library跟踪(我们使用的是5.0版本)-总的来说,有点麻烦。这发生在Windows Server 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.&lt;UpdateUsers&gt;d__1a.MoveNext()

  Exception rethrown at [0]:
  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.&lt;SetException&gt;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)为null。

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");
    }
}

你正在修改 LogEntry.BuildCategoriesCollection 吗? - Daniel A. White
你能否在调用 UpdateUsers 的地方添加你的 ViewModelTest 代码? - Dave Zych
我们需要一些额外的信息。例如,我们需要知道导致异常的方法输入。当然,问题显然出在Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry.BuildCategoriesCollection(String category)中,所以要捕获异常。 - Security Hound
我已经更新了问题,并加入了你们所询问的额外信息。 - JMV
罕见(间歇性)错误通常是由多线程代码中的竞争条件引起的。您是否有任何情况下,对象在被修改时可能会被其他线程观察到(没有锁)? - William
我有很多异步方法,使用此方法:using (traceMgr.StartTrace("Trace")). 如果企业库日志记录功能不是线程安全的,那可能就是您所说的一个实例了吗? - JMV
1个回答

1
这个问题似乎在之前的E-Lib版本中也是一个已知的bug。
称为:在使用多个线程时,使用日志记录AB时出现未处理的异常。
“根本问题在于,在.NET 2.0 RTM中,如果在创建子线程时存在父线程的操作堆栈,则该堆栈将与其子级共享。”
在此处阅读更多信息: http://entlib.codeplex.com/workitem/9592 很难建议一种通用解决方案,因为它非常依赖于您的应用程序架构。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接