how to fix “'System.AggregateException' oc

2019-01-22 17:14发布

I receive such problem in debugger and program stops executing. Debugger doesn't show me the line so I don't know what to fix.

An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll

Additional information: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.

Cannot obtain value of local or argument '' as it is not available at this instruction pointer, possibly because it has been optimized away. System.Threading.Tasks.TaskExceptionHolder

How to troubleshoot my problem?

I also found this question which is pretty similar Cannot obtain value of local or argument as it is not available at this instruction pointer, possibly because it has been optimized away

4条回答
唯我独甜
2楼-- · 2019-01-22 17:34

In my case I ran on this problem while using Edge.js — all the problem was a JavaScript syntax error inside a C# Edge.js function definition.

查看更多
趁早两清
3楼-- · 2019-01-22 17:46

You could handle the exception directly so it would not crash your program (catching the AggregateException). You could also look at the Inner Exception, this will give you a more detailed explanation of what went wrong:

try {
    // your code 
} catch (AggregateException e) {

}
查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-22 17:47

As the message says, you have a task which threw an unhandled exception.

Turn on Break on All Exceptions (Debug, Exceptions) and rerun the program.
This will show you the original exception when it was thrown in the first place.


(comment appended): In VS2015 (or above). Select Debug > Options > Debugging > General and unselect the "Enable Just My Code" option.

查看更多
再贱就再见
5楼-- · 2019-01-22 17:53

The accepted answer will work if you can easily reproduce the issue. However, as a matter of best practice, you should be catching any exceptions (and logging) that are executed within a task. Otherwise, your application will crash if anything unexpected occurs within the task.

Task.Factory.StartNew(x=>
   throw new Exception("I didn't account for this");
)

However, if we do this, at least the application does not crash.

Task.Factory.StartNew(x=>
   try {
      throw new Exception("I didn't account for this");
   }
   catch(Exception ex) {
      //Log ex
   }
)
查看更多
登录 后发表回答