发生时,在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

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

问题描述

Am创建了一个 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(对象状态)消息:对象引用未设置为对象的实例.

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天全站免登陆