当它发生时 System.Windows.ni.dll 中发生类型为“'System.Reflection.TargetInvocationException'的未处理异常"在Windows Phone [英] When it occurs An unhandled exception of type "'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll" inWindows Phone

查看:11
本文介绍了当它发生时 System.Windows.ni.dll 中发生类型为“'System.Reflection.TargetInvocationException'的未处理异常"在Windows Phone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Am creating a WP8 application which uses Web Service to fetch,create,update & delete data & displaying it.
Now the problem is that my application crashes by throwing

未处理的异常类型'System.Reflection.TargetInvocationException' 发生在Windows Phone 中的 System.Windows.ni.dll"

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

没有针对此异常的堆栈跟踪 &我坚持了几个小时.而且我注意到每当调用服务比平时更频繁时就会发生这种异常,但我没有得到真正的原因.

There is no stack trace for this exception & i am stuck with this one for hours. And i noticed that this exception occurs whenever calling the service more frequently than normal but i didn't get the actual reason.

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

It is really helpful to know
1.What type of exception is this ?
2.At what condition this will happen ?
3.How we can handle the app crash because of this exception?

推荐答案

您的评论

你说得对.必须有一个内部异常对象说在 MyApp.ViewModels.CreateViewModel.d__61.MoveNext() --- 从上一个抛出异常的位置的堆栈跟踪结束 --- 在 System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__0(Object state)" 消息:未将对象引用设置为对象的实例.

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.

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

just shows that somewhere, you're invoking an async method which is not awaited: when a method returns a task, always await it.

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

Your inner exception should have an inner exception (i.e. $exception.InnerException.InnerException whiches stacktrace will show you the location of your NullReferenceException)

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

UnhandledException event is invoked when an exception in your code has not been handled by your code, and the app doesnt know how to handle it. By default, it makes your app crash. However, you can prevent your app from crashing in those cases. See this to know more about it.

要以干净的方式"解决您的问题,您必须找到不等待您的代码的地方,并修复它.即你会找到的地方:

To fix your issue "the clean way", you will have to find the place where your code is not awaited, and fix it. ie somewhere you will find:

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

改变它:

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

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

[edit] this will handle the error, but what you really want to fix is the cause of your nullref exception. I dont have that much clues, but it looks like a thread concurrency issue.

这篇关于当它发生时 System.Windows.ni.dll 中发生类型为“'System.Reflection.TargetInvocationException'的未处理异常"在Windows Phone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆