简体   繁体   English

如何修复 mscorlib.dll 中发生“'System.AggregateException'”

[英]How to fix “'System.AggregateException' occurred in mscorlib.dll”

I'm receiving an unhandled exception while debugging, and the program stops executing.我在调试时收到一个未处理的异常,程序停止执行。 The 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 mscorlib.dll发生类型为“ System.AggregateException ”的未处理异常

Additional information: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property.附加信息:等待任务或访问其 Exception 属性均未观察到任务的异常。 As a result, the unobserved exception was rethrown by the finalizer thread.结果,未观察到的异常被终结器线程重新抛出。

Cannot obtain value of local or argument ' <this> ' as it is not available at this instruction pointer, possibly because it has been optimized away.无法获取本地或参数“ <this> ”的值,因为它在此指令指针处不可用,可能是因为它已被优化掉。 System.Threading.Tasks.TaskExceptionHolder

How can I troubleshoot this problem?我该如何解决这个问题?

I also found this question which is pretty similar.我也发现this question非常相似。

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.打开 Break on All Exceptions (Debug, Exceptions) 并重新运行程序。
This will show you the original exception when it was thrown in the first place.这将向您显示最初抛出的原始异常。


(comment appended): In VS2015 (or above). (附注):在 VS2015(或更高版本)中。 Select Debug > Options > Debugging > General and unselect the "Enable Just My Code" option.选择调试 > 选项 > 调试 > 常规并取消选择“仅启用我的代码”选项。

You could handle the exception directly so it would not crash your program (catching the AggregateException ).您可以直接处理异常,以免程序崩溃(捕获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) {

}

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

就我而言,我在使用 Edge.js 时遇到了这个问题——所有问题都是 C# Edge.js 函数定义中的 JavaScript 语法错误。

System.AggregateException HResult=0x80131500 Mensaje = Se han producido uno o varios errores. System.AggregateException HResult = 0x80131500 Mensaje =随机产生产品错误。 Origen = mscorlib Seguimiento de la pila: en System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) en System.Threading.Tasks.Task 1.GetResultCore(Boolean waitCompletionNotification) en System.Threading.Tasks.Task 1.get_Result() en Itrebol.Presentation.FormularioTerceros.<>c__DisplayClass26_0.b__1(Task 1 readTask) en C:\\Users\\GonzaloAlfonso\\source\\repos\\ServicioItrebol - copia\\Itrebol.Presentation\\FormularioTerceros.xaml.cs: línea 535 en System.Threading.Tasks.ContinuationTaskFromResultTask 1.InnerInvoke() en System.Threading.Tasks.Task.Execute() Excepción interna 1: JsonSerializationException: Cannot deserialize the current JSON object (eg {"name":"value"}) into type 'System.Collections.Generic.List`1[Itrebol.Dato.Modelo.TERCEROS]' because the type requires a JSON array (eg [1,2,3]) to deserialize correctly. Origen = mscorlib,请执行以下操作:zh-cn System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)zh- 1.GetResultCore(Boolean waitCompletionNotification) en System.Threading.Tasks.Task System.Threading.Tasks.Task 1.GetResultCore(Boolean waitCompletionNotification) en System.Threading.Tasks.Task CN 1.GetResultCore(Boolean waitCompletionNotification) en System.Threading.Tasks.Task 1.get_Result() zh_cn Itrebol.Presentation.FormularioTerceros。<> c__DisplayClass26_0.b__1(任务1 readTask) en C:\\Users\\GonzaloAlfonso\\source\\repos\\ServicioItrebol - copia\\Itrebol.Presentation\\FormularioTerceros.xaml.cs: línea 535 en System.Threading.Tasks.ContinuationTaskFromResultTask 1.InnerInvoke() 1 readTask) en C:\\Users\\GonzaloAlfonso\\source\\repos\\ServicioItrebol - copia\\Itrebol.Presentation\\FormularioTerceros.xaml.cs: línea 535 en System.Threading.Tasks.ContinuationTaskFromResultTask于System.Threading.Tasks.Task.Execute()实例1:JsonSerializationException:无法将当前JSON对象(例如{“ name”:“ value”})反序列化为类型'System.Collections .Generic.List`1 [Itrebol.Dato.Modelo.TERCEROS]',因为类型需要JSON数组(例如[1,2,3])才能正确反序列化。 To fix this error either change the JSON to a JSON array (eg [1,2,3]) or change the deserialized type so that it is a normal .NET type (eg not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. 要解决此错误,可以将JSON更改为JSON数组(例如[1,2,3]),也可以更改反序列化类型,使其成为普通的.NET类型(例如,不像整数这样的原始类型,也不像这样的集合类型)数组或列表),可以从JSON对象反序列化。 JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. 还可以将JsonObjectAttribute添加到类型中,以强制其从JSON对象反序列化。 Path 'Message', line 1, position 21. 路径“消息”,第1行,位置21。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用Google API进行身份验证时,mscorlib.dll中发生“ System.AggregateException” - 'System.AggregateException' occurred in mscorlib.dll, when trying to authenicate using Google API Telegram Bot 因 mscorlib.dll 中发生类型为“System.AggregateException”的未处理异常而停止 - Telegram Bot stops with An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll 我如何修复mscorlib.dll中发生的&#39;System.FormatException&#39; - how can i fix 'System.FormatException' occurred in mscorlib.dll 一致滚动后如何修复mscorlib.dll中发生的&#39;System.OutOfMemoryException&#39; - How to fix 'System.OutOfMemoryException' occurred in mscorlib.dll after unison scrolling mscorlib.dll 中出现“System.StackOverflowException”? - 'System.StackOverflowException' occurred in mscorlib.dll? mscorlib.dll中发生'System.ArgumentOutOfRangeException' - 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll 发生PingException mscorlib.dll - PingException occurred mscorlib.dll mscorlib.dll中发生了类型为&#39;System.InvalidOperationException&#39;的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll mscorlib.dll中发生了&#39;System.FormatException&#39;类型的未处理异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生了未处理的“System.StackOverflowException”类型异常 - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM