这个程序在我的开发用的电脑上一切正常,
但是到了打包后安装到别的电脑上就提示这个“未将对象引用设置到对象的实例”
然后在开发电脑上安装这个软件也是运行正常的,
搞不明白了,大家指点一下我吧。
有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。************** 异常文本 **************
System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 注册机.CommonClass.SoftReg.GetDiskVolumeSerialNumber()
   在 注册机.CommonClass.SoftReg.getMNum()
   在 注册机.Form1.Form1_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.ContainerControl.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
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.42 (RTM.050727-4200)
    基本代码:  file:///C:/WINDOWS/Microsoft.NET/Framework 2.0.50727/mscorlib.dll
----------------------------------------
注册机
    程序集版本: 1.0.0.0
    Win32 版本: 1.0.0.0
    基本代码:  file:///C:/Program%20Files/Lenovo%20(Beijing)%20Limited/Setup1/注册机.exe
----------------------------------------
System.Windows.Forms
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.42 (RTM.050727-4200)
    基本代码:  file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.42 (RTM.050727-4200)
    基本代码:  file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.42 (RTM.050727-4200)
    基本代码:  file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Management
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.42 (RTM.050727-4200)
    基本代码:  file:///C:/WINDOWS/assembly/GAC_MSIL/System.Management/2.0.0.0__b03f5f7f11d50a3a/System.Management.dll
----------------------------------------
mscorlib.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.42 (RTM.050727-4200)
    基本代码:  file:///C:/WINDOWS/Microsoft.NET/Framework 2.0.50727/mscorlib.dll
----------------------------------------
System.Windows.Forms.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.42 (RTM.050727-4200)
    基本代码:  file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。例如: <configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。

解决方案 »

  1.   

    GetDiskVolumeSerialNumber() 方法里的代码贴下把..那个值没有取到. 结果为NULL.你使用了一个null
      

  2.   

            public string GetDiskVolumeSerialNumber()
            {
               //get   information   of   Harddisk     
                string strDiskSN = "";
                ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
                ManagementObjectCollection disk = mc.GetInstances();
                foreach (ManagementObject one in disk)
                {
                    strDiskSN = one["SerialNumber"].ToString();
                    break;
                }  
                return strDiskSN;
            
            }
      

  3.   

    更换使用WMI服务....你的目标机器可能没启动WMI服务.然后你获取的mc为空了把..
    ManagementClass mc = new ManagementClass("Win32_PhysicalMedia"); 
    if(mc==null)
    {
    MessageBox.Show("错误mc为空!");
    return "";
    }
    这样看看.
      

  4.   

    再不就是 strDiskSN = one["SerialNumber"].ToString(); 这个错误了One["SerialNumber"] 这个为null了
      

  5.   

    你开发的电脑是什么系统,安装到别人电脑又是什么系统?
    ManagementClass这个类需要WMI支持
    而且需要一定权限否则one["SerialNumber"]就是NULL值
      

  6.   

    没MSGBOX弹出,还是直接报错
      

  7.   


    都是XP,都用的ADMIN,目标机的WMI也是开着的,下面是目标机上的360里的启动的服务信息。
    名称:winmgmt
    组别:O23 - 系统服务
    安全级别: 安全
    命令行:C:\WINDOWS\system32\wbem\WMIsvc.dll
    文件描述:WMI
    出品公司:Microsoft Corporation
    文件大小:141 KB
    文件版本:5.1.2600.5512
    MD5值:0e83443a90dc888f40a25fee74bf877f
    推荐操作:此项为安全项,我们建议您不进行任何修复操作。
    修复方式:我们仅提供暂停操作,如果您想彻底关闭该服务,请手动进行关闭
      

  8.   

     在 注册机.CommonClass.SoftReg.GetDiskVolumeSerialNumber() 
     在 注册机.CommonClass.SoftReg.getMNum() 
    这两个都是在类里的,而且添加了using System.Management;
    这个在打包时要不要什么特别的注明的啊?
      

  9.   

    应该是这句代码出现了空引用:
    strDiskSN = one["SerialNumber"].ToString(); 
    也就是 SerialNumber 没有。
      

  10.   

    我都改成这样了,还是直接报错,有没有什么好的调试办法啊?            string strDiskSN = "";
                ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
                if (null == mc) 
                {
                    MessageBox.Show("MC=NULL");
                    return"111111111111";
                }
                ManagementObjectCollection disk = mc.GetInstances();
                if (null == disk)
                {
                    MessageBox.Show("disk=null");
                    return "22222222222";
                }
                foreach (ManagementObject one in disk)
                {
                    strDiskSN = one["SerialNumber"].ToString();
                    return "3333333333333";
                    break;
                    //if (null == one["SerialNumber"])
                    //{
                    //    MessageBox.Show("strDiskSN=null");
                    //    return "aaaaaaaaaaa";
                    //}
                }
                //return strDiskSN;
                return "44444444444";另外
    Win32_PhysicalMediaThe Win32_PhysicalMedia class represents any type of documentation or storage medium, such as tapes, CD ROMs and so on. To obtain the characteristics of the media in a CD drive, such as whether it is writeable, use Win32_CDROMDrive and the Capabilities property.The following syntax is simplified from MOF code and includes all inherited properties.
    class Win32_PhysicalMedia : CIM_PhysicalMedia
    {
      uint64 Capacity;
      string Caption;
      boolean CleanerMedia;
      string CreationClassName;
      string Description;
      boolean HotSwappable;
      datetime InstallDate;
      string Manufacturer;
      string MediaDescription;
      uint16 MediaType;
      string Model;
      string Name;
      string OtherIdentifyingInfo;
      string PartNumber;
      boolean PoweredOn;
      boolean Removable;
      boolean Replaceable;
      string SerialNumber = NULL;
      string SKU;
      string Status;
      string Tag = NULL;
      string Version;
      boolean WriteProtectOn;
    };
    和这里的SerialNumber=NULL;有没有什么关系啊?