how to fix “'System.AggregateException' occurred in mscorlib.dll”

偶尔善良 提交于 2019-11-27 13:25:43

问题


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


回答1:


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.




回答2:


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) {

}



回答3:


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
   }
)



回答4:


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.




回答5:


System.AggregateException HResult=0x80131500 Mensaje = Se han producido uno o varios errores. Origen = mscorlib Seguimiento de la pila: en System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) en System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) en System.Threading.Tasks.Task1.get_Result() en Itrebol.Presentation.FormularioTerceros.<>c__DisplayClass26_0.b__1(Task1 readTask) en C:\Users\GonzaloAlfonso\source\repos\ServicioItrebol - copia\Itrebol.Presentation\FormularioTerceros.xaml.cs: línea 535 en System.Threading.Tasks.ContinuationTaskFromResultTask1.InnerInvoke() en System.Threading.Tasks.Task.Execute() Excepción interna 1: JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Itrebol.Dato.Modelo.TERCEROS]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'Message', line 1, position 21.



来源:https://stackoverflow.com/questions/11122092/how-to-fix-system-aggregateexception-occurred-in-mscorlib-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!