我的一个C#应用程序打包时出现一个这样的错误,哪位高手知道这个原因请指点!
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Control.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.AxHost.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
P2PClient
    Assembly Version: 1.0.2296.29350
    Win32 Version: 1.0.2296.29350
    CodeBase: file:///C:/Program%20Files/RJSoft/千年远程教育专家/P2PClient.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
AxInterop.SHDocVw
    Assembly Version: 1.1.0.0
    Win32 Version: 1.1.0.0
    CodeBase: file:///C:/Program%20Files/RJSoft/千年远程教育专家/AxInterop.SHDocVw.DLL
----------------------------------------
NSButton
    Assembly Version: 1.0.1473.27711
    Win32 Version: 1.0.1473.27711
    CodeBase: file:///C:/Program%20Files/RJSoft/千年远程教育专家/NSButton.DLL
----------------------------------------
AxInterop.RealAudioObjects
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/RJSoft/千年远程教育专家/AxInterop.RealAudioObjects.DLL
----------------------------------------
Interop.SHDocVw
    Assembly Version: 1.1.0.0
    Win32 Version: 1.1.0.0
    CodeBase: file:///C:/Program%20Files/RJSoft/千年远程教育专家/Interop.SHDocVw.DLL
----------------------------------------
Accessibility
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/accessibility/1.0.5000.0__b03f5f7f11d50a3a/accessibility.dll
----------------------------------------
Interop.RealAudioObjects
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/RJSoft/千年远程教育专家/Interop.RealAudioObjects.DLL
----------------------------------------
Sloppycode.Controls.WebBrowserEx
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/RJSoft/千年远程教育专家/Sloppycode.Controls.WebBrowserEx.DLL
----------------------------------------
Microsoft.mshtml
    Assembly Version: 7.0.3300.0
    Win32 Version: 7.0.3300.0
    CodeBase: file:///C:/Program%20Files/RJSoft/千年远程教育专家/Microsoft.mshtml.DLL
----------------------------------------
System.Data
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system.data/1.0.5000.0__b77a5c561934e089/system.data.dll
----------------------------------------
System.Xml
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/winnt/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.For example:<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.

解决方案 »

  1.   

    是在运行程序的时候出现这个错误,我已经在打包时安装了.NETFRAMEWORK和J#运行库,但是不知道这个是什么原因造成的,而且 不是每台电脑都出现这个错误,出现这个错误的电脑操作平台是WIN2000,
      

  2.   

    错误的原因是:
    未将引用的对象设置到对象的实例。逐步跟踪你的代码,看看调用函数时,哪个参数是空引用(null),并设法将它设置到一个实例。尤其注意跟踪堆栈里的那些方法。如果实在没有,可能是 .Net 的一个 Bug。
      

  3.   

    zCheng(NullRefrenceException) :
    在我开发的环境里面不会出现这个错误,但是在没有装开发环境(VS.NET2003)的电脑里面才会出现这个错误。
      

  4.   

    晕……你发布软件时是不是忘记把配置文件之类的东西发布了?对比两个环境用什么不同(比如文件列表等)。要不这样,让程序启动时,每经过一定的步骤(调用方法前,调用方法后)将状态写入一个日志文件(记得要让 writer.Flush() 立即更新文件内容),然后看看启动失败的程序停在哪里。如:static void Main()
    {
       StreamWriter writer = new StreamWriter("log.txt");
       wrtier.WriteLine("Starting program...");
       writer.Write("Enabling Visual Style...");
       writer.Flush();
       Application.EnableVisualStyles();
       writer.WriteLine("Success");
       writer.Write("Dealing Message Loop Querry...");
       writer.Flush();
       Application.DoEvents();
       writer.WriteLine("Success");
       writer.Write("Initializing Main Window...");
       writer.Flush();
       Application.Run(new MainWnd()); 
    }
    //.....public MainWnd()
    {
       writer.Write("Initializing Components...");
       writer.Flush(); 
       InitializeComponents();
       writer.WriteLine("Success");
       writer.Write("Initializing Configuration...");
       writer.Flush();
       LoadConfiguration();
       writer.WriteLine("Success");
       writer.Write("Loading Files...");
       LoadFiles();
       writer.WriteLine("Success");
       writer.Flush();
    }