就是你使用了一个空的对象,举个例子:
string username = item.Title.toString();
如果item.Title为null,如果这个时候再使用toString方法,就会报
未将对象引用设置到对象的实例未将对象引用设置到对象的实例的错误。
因为toString只对一个存在的对象有效。
因此一般情况下,如果你不确定,最好在使用一个对象之前进行是否为null的判断。
就是你使用了一个空的对象,举个例子:
string username = item.Title.toString();
如果item.Title为null,如果这个时候再使用toString方法,就会报
未将对象引用设置到对象的实例未将对象引用设置到对象的实例的错误。因为toString只对一个存在的对象有效。
因此一般情况下,如果你不确定,最好在使用一个对象之前进行是否为null的判断。
转载于:https://www.cnblogs.com/NewWork/archive/2013/06/04/3260561.html
有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。
************** 异常文本 **************
System.NullReferenceException: 未将对象引用设置到对象的实例。
在 SSTap.View.LoginForm.LoginForm_Load(Object sender, EventArgs e)
在 System.Windows.Forms.Form.OnLoad(EventArgs e)
在 System.Windows.Forms.Form.OnCreateControl()
在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
在 System.Windows.Forms.Control.CreateControl()
在 System.Windows.Forms.Control.WmShowWindow(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WmShowWindow(Message& m)
在 System.Windows.Forms.Form.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** 已加载的程序集 **************
mscorlib
程序集版本:4.0.0.0
Win32 版本:4.8.4010.0 built by: NET48REL1LAST_B
基本代码:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
SS-TAP_对接91
程序集版本:30.5.26.2
Win32 版本:
基本代码:file:///C:/Program%20Files%20(x86)/dingdang/ddjiasu/dingdang.exe
----------------------------------------
System.Windows.Forms
程序集版本:4.0.0.0
Win32 版本:4.8.4001.0 built by: NET48REL1LAST_C
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
程序集版本:4.0.0.0
Win32 版本:4.8.4001.0 built by: NET48REL1LAST_C
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
程序集版本:4.0.0.0
Win32 版本:4.8.3752.0 built by: NET48REL1
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
RestSharp
程序集版本:106.1.0.0
Win32 版本:
基本代码:file:///C:/Program%20Files%20(x86)/dingdang/ddjiasu/dingdang.exe
----------------------------------------
Newtonsoft.Json
程序集版本:10.0.0.0
Win32 版本:
基本代码:file:///C:/Program%20Files%20(x86)/dingdang/ddjiasu/dingdang.exe
----------------------------------------
System.Core
程序集版本:4.0.0.0
Win32 版本:4.8.4001.0 built by: NET48REL1LAST_C
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Configuration
程序集版本:4.0.0.0
Win32 版本:4.8.3752.0 built by: NET48REL1
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
程序集版本:4.0.0.0
Win32 版本:4.8.3752.0 built by: NET48REL1
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Numerics
程序集版本:4.0.0.0
Win32 版本:4.8.3752.0 built by: NET48REL1
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Runtime.Serialization
程序集版本:4.0.0.0
Win32 版本:4.8.3825.0 built by: NET48REL1LAST_B
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
System.Data
程序集版本:4.0.0.0
Win32 版本:4.8.3752.0 built by: NET48REL1
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
mscorlib.resources
程序集版本:4.0.0.0
Win32 版本:4.8.3752.0 built by: NET48REL1
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Windows.Forms.resources
程序集版本:4.0.0.0
Win32 版本:4.8.3752.0 built by: NET48REL1
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。
例如:
启用 JIT 调试后,任何未经处理的异常
都将被发送到在此计算机上注册的 JIT 调试程序,
而不是由此对话框处理。
三、解决方案:
1局部调试:设置断点、在浏览器打开要调试的页面。若断点调试无效,则:
2使用进程调试:工具-附加到进程-选中当前要调试的进程(通常是w3wp)-- 运行(当前主进程)
一、常见原因
1、ViewState 对象为Null。
2、DateSet 空。
3、sql语句或Datebase的原因导致DataReader空。
4、声明字符串变量时未赋空值就应用变量。
5、未用new初始化对象。
6、Session对象为空。
7、对控件赋文本值时,值不存在。
8、使用Request.QueryString()时,所获取的对象不存在,或在值为空时未赋初始值。
9、使用FindControl时,控件不存在却没有做预处理。
10、重复定义造成未将对象引用设置到对象的实例错误.
二、案例分析:
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误: 行 24:
// stringTemp = stringTemp.Replace("@ID", mainModel.ID.ToString()).Replace("@title", mainModel.title).Replace("@people", mainModel.people);
行 25: 行 26:
stringTemp =stringTemp.Replace("@ID", mainModel.ID.ToString()).Replace("@title", mainModel.title).Replace("@people", mainModel.people);
行 27: 行 28:
context.Response.Write(stringTemp);
源文件: F:\vs_object\ThreeLayerWebDemo\WebDemo\WebDemo\Web\News\EditNews.ashx.cs 行: 26