ManualResetEvent.WaitOne () throws NullReferenceException: Object reference not set to object instance

I have a weird random NPE error while working with ManualResetEvent.WaitOne (). Here is my code.

I have a method that creates a ManualResetEvent object and then passes it to a Windows Workflow Foundation (WWF) workflow instance as one of the dependency parameters (manualResetEvent), and then I go into the manualResetEvent.WaitOne () API.

ManualResetEvent manResetEvt = new ManualResetEvent(false);

Dictionary<String, Object> wfArgs = new Dictionary<string, object>();
wfArgs["manualResetEvent"] = manResetEvt;

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(MyWWFProcess), wfArgs);

instance.Start();
manResetEvt.WaitOne();

      

When the job is done in WWF, I just call manualResetEvent.set ().

if (this.manualResetEvent != null)
{
    this.manualResetEvent.Set();
}

      

All of these compilations are good and while running, I can see that the thread is hitting the WWF as expected and the caller is waiting for the WaitOne () call too.

The moment WWF calls manualResetEvent.Set () to notify the caller, I see an NPE exception with the caller NOT WWF.

System.NullReferenceException: Object reference not set to object instance.

I really don't know where this exception comes from. When I debug this code in VS IDE everything works fine, but only when with the application in Release mode I see this exception.

What am I doing wrong here?

+3


source to share


2 answers


I found the answer to my question. Based on James Thorpe's suggestion, I printed out the stack trace from the exception and it turned out that the application was sending a NULL data point when this method was called, and WaitOne () was not calling NPE. When I ran the unit test from the VS IDE debugger, I passed in good value, so no exception was found. After fixing the caller method, everything works well. Thanks to everyone who figured out the ideas to fix this issue.



0


source


You need to add the object to the dictionary



Dictionary<String, Object> wfArgs = new Dictionary<string, object>();
wfArgs.Add("manualResetEvent", manResetEvt);

      

-1


source







All Articles