7

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.&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>

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");
    }
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
JMV
  • 101
  • 1
  • 5
  • are you modifying `LogEntry.BuildCategoriesCollection`? – Daniel A. White Oct 22 '12 at 17:16
  • Can you add your `ViewModelTest` code where you are calling `UpdateUsers`? – Dave Zych Oct 22 '12 at 17:18
  • We need some additional information. For example we need to know the input to the method causing the exception. Of course the problem is clearly in `Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry.BuildCategoriesCollection(String category)` so catch the exception. – Security Hound Oct 22 '12 at 17:54
  • I've updated the question with the extra information you guys have asked about. – JMV Oct 24 '12 at 09:01
  • Rare (intermittent) errors are often caused by race conditions in multi-threaded code. Do you have any cases where an object is being modified when it might be possible for other threads to observe it (without a lock) ? – William Oct 25 '12 at 21:53
  • I have async methods in abundance using this: using (traceMgr.StartTrace("Trace")). If the enterprise lib logging functionality is not thread safe, that could be one instance of what you're saying? – JMV Oct 26 '12 at 07:40

1 Answers1

1

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.

G.Y
  • 6,042
  • 2
  • 37
  • 54