c# - 企业库错误

标签 c# enterprise-library

我收到了关于我们的实时环境中出现罕见的间歇性错误的报告。我尝试重现它但没有成功,错误本身有点神秘。除此之外,它似乎涉及企业库跟踪(我们使用的是 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.&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) 的输入为空。

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/

相关文章:

c# - Enterprise Library 异常处理 6.0 XML 日志记录不写入文件

C# 初学者 - 在同一个函数中回调

c# - WPF ListViewItem 事件未在触摸屏上正确触发

c# - TeamCity - 重新运行特定的构建步骤

c#-4.0 - 为什么我必须在客户端代码中引用 ExceptionHandling.Logging dll?

c# - 与 Microsoft Enterprise Library 共享 MySQL 连接

c# - 在 silverlight 中使用 while(true) 会很危险吗?

c# - 删除 KeyDown 事件后的延迟?

java - 公共(public) JAR 是否必须在 EAR 中的 WAR 中重复?

asp.net - 通过 smtppickupfolder 使用 MS 企业库日志记录应用程序 block 发送电子邮件?