I'm receiving reports of a rare and intermittent error in our live environment. I have been unsuccessful in my attempts to reproduce it, and the error itself is a slight mystery. Add to that, it seems to be something involving Enterprise Library tracing (we're using version 5.0) - all in all, a bit of a pain. This is happening on Windows Sever 2008, application is on .Net Framework 4.0 (WPF).
The error message and the stack trace follow:
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>
Can anyone shed any light on what might be causing this?
EDIT: I'm not modifying LogEntry.BuildCategoriesCollection. The input to the method BuildCategoriesCollection(String category) is null.
The UpdateUsers method is as follows:
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");
    }
}
                This problem seem to be a known bug for E-Lib in previous versions too.
Known as: Unhandled exception when using the logging AB from multiple threads.
"The underlying issue is that in .NET 2.0 RTM a parent thread's operation stack was shared with its children if such a stack existed by the time the children were created."
Read more here: http://entlib.codeplex.com/workitem/9592
Hard to suggest a generic solution to this as it is very depends on the architecture of your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With