gpt4 book ai didi

c# - 当它发生在Windows Phone中的System.Windows.ni.dll中发生了类型为 "' System.Reflection.TargetInvocationException'的未处理异常

转载 作者:可可西里 更新时间:2023-11-01 08:21:22 24 4
gpt4 key购买 nike

我正在创建一个 WP8 应用程序,它使用 Web 服务 来获取、创建、更新和删除数据并显示它。
现在的问题是我的应用程序因抛出而崩溃

An unhandled exception of type "'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll" inWindows Phone

enter image description here

此异常没有堆栈跟踪,我被这个异常困了几个小时。我注意到每当调用服务比正常情况更频繁时就会发生此异常,但我没有得到真正的原因。

了解
真的很有帮助1.这是什么类型的异常?
2.在什么情况下会发生这种情况?
3.我们如何处理由于此异常导致的应用程序崩溃?

最佳答案

你的评论

You are right . gotta an inner exception object says " at MyApp.ViewModels.CreateViewModel.d__61.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__0(Object state) " Message : Object reference not set to an instance of an object.

只是表明在某个地方,您正在调用一个不等待的异步方法:当一个方法返回一个任务时,总是等待它。

您的内部异常应该有一个内部异常(即 $exception.InnerException.InnerException 堆栈跟踪将向您显示 NullReferenceException 的位置)

UnhandledException 事件在您的代码未处理代码中的异常时调用,应用程序不知道如何处理它。默认情况下,它会使您的应用程序崩溃。但是,您可以防止您的应用程序在这些情况下崩溃。参见 this了解更多。

要“以干净的方式”解决您的问题,您必须找到不等待您的代码的地方,然后修复它。即在某个地方你会发现:

myObject.DoSomethingAsync(); // DoSomethingAsync() returns a task.

改变它:

try
{
await myObject.DoSomethingAsync(); // DoSomethingAsync() returns a task.
}catch(Exception ex)
{
// display error message or whatever
}

[edit] 这将处理错误,但您真正想要修复的是 nullref 异常的原因。我没有那么多线索,但看起来像是线程并发问题。

关于c# - 当它发生在Windows Phone中的System.Windows.ni.dll中发生了类型为 "' System.Reflection.TargetInvocationException'的未处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20262388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com