AJAX问题“对象引用未设置为对象的实例".我该如何解决..? [英] AJAX problem "Object reference not set to an instance of an object". How can I solve this..?

查看:176
本文介绍了AJAX问题“对象引用未设置为对象的实例".我该如何解决..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Visual Studio 2010中使用AJAX时,有calenderextender,文件上传和其他文件可以正常运行,但是在拖动"窗格,下拉"窗格,"AnimationExtender"中有相同的错误.我该如何解决此错误?

While I am Using AJAX in visual studio 2010 there is calenderextender, file upload and others are run properly but, I have same error in Drag pane, Drop Down pane, AnimationExtender. How can i solve this errors?

推荐答案

这不是"AJAX问题".这是一个普遍的问题,一个非常简单的问题,因此它甚至不是很大的问题.有趣的是,您建议某人解决没有代码示例的问题.但这不是问题,因为您需要自己解决所有此类问题".每当遇到类似问题时,您都无法提出问题.

您没有显示在何处抛出异常消息对象引用未设置为对象的实例".

不要担心.这是最容易检测和修复的情况之一.它仅表示使用和实例(非静态)成员对某个引用类型的某个成员/变量进行了取消引用,这要求该成员/变量为非null,但实际上它似乎为null.只需在调试器下执行它,它将在引发异常的位置停止执行.在该行上放置一个断点,重新启动应用程序,然后再次到达该点.评估下一行中涉及的所有引用,看看哪一个为空,而不必为空.在弄清楚这一点之后,请修复代码:确保将成员/变量正确初始化为非null引用,或者检查它是否为null,如果为null,则执行其他操作.

另请参见:要在单击按钮时显示下一条记录.但在下一个记录功能对象引用未设置为对象实例"的条件下出现错误 [ http://msdn.microsoft.com/en-us/library/system.exception.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.exception. stacktrace.aspx [ ^ ].

堆栈跟踪只是一个字符串,显示了从throw语句到处理程序的异常传播的完整路径.通过阅读它,您始终可以找到目标.对于日志记录,最好(在大多数情况下)使用类System.Diagnostics.EventLog:
http://msdn.microsoft.com/en-us/library/system.diagnostics. eventlog.aspx [ ^ ].

祝你好运,
—SA
This is not "AJAX problem". This is a general problem, a very easy one, so it''s not even very much of a problem. Only it''s funny that you suggested someone to solve your problem having no code sample. But even this is not a problem, because you need to solve such "problems" all by yourself. You cannot ask question every time you face similar issues.

You did not show where the exception with the message "Object reference not set to an instance of an object" is thrown.

Not to worry. This is one of the very easiest cases to detect and fix. It simply means that some member/variable of some reference type is dereferenced by using and of its instance (non-static) members, which requires this member/variable to be non-null, but in fact it appears to be null. Simply execute it under debugger, it will stop the execution where the exception is thrown. Put a break point on that line, restart the application and come to this point again. Evaluate all references involved in next line and see which one is null while it needs to be not null. After you figure this out, fix the code: either make sure the member/variable is properly initialized to a non-null reference, or check it for null and, in case of null, do something else.

Please see also: want to display next record on button click. but got an error in if condition of next record function "object reference not set to an instance of an object"[^].

Sometimes, you cannot do it under debugger, by one or another reason. One really nasty case is when the problem is only manifested if software is built when debug information is not available. In this case, you have to use the harder way. First, you need to make sure that you never block propagation of exceptions by handling them silently (this is a crime of developers against themselves, yet very usual). The you need to catch absolutely all exceptions on the very top stack frame of each thread. You can do it if you handle the exceptions of the type System.Exception. In the handler, you need to log all the exception information, especially the System.Exception.StackTrace:
http://msdn.microsoft.com/en-us/library/system.exception.aspx[^],
http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx[^].

The stack trace is just a string showing the full path of exception propagation from the throw statement to the handler. By reading it, you can always find ends. For logging, it''s the best (in most cases) to use the class System.Diagnostics.EventLog:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].

Good luck,
—SA


这篇关于AJAX问题“对象引用未设置为对象的实例".我该如何解决..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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