发生未处理的异常(当 运行 已安装应用程序时)

Unhandled exception has occurred (when running installed application)

我使用 installshield 编译一个应用程序,它在调试期间或在使用 VS 编译和发布时运行良好。

当我 运行 安装的应用程序时,我收到以下错误消息:

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text ************** System.ArgumentNullException: Value cannot be null. Parameter name: path at System.IO.File.AppendAllText(String path, String contents) at SerialPortListener.MainForm.MainForm_Load(Object sender, EventArgs e) in c:\Users\Jamie\Documents\SerialPortListener\SerialPortListener\MainForm.cs:line 291 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies ************** mscorlib Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll ---------------------------------------- SerialPortListener Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0 CodeBase: file:///C:/Program%20Files%20(x86)/P%26L%20Software/P%26L%20Hardware%20Helper/SerialPortListener/obj/x86/Debug/SerialPortListener.exe ---------------------------------------- System.Windows.Forms Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- System.Drawing Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ---------------------------------------- System Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34238 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll ---------------------------------------- System.Configuration Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll ---------------------------------------- System.Xml Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34234 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- Accessibility Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL

CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll

************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (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:

When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.

我试过按照它说的做并启用 jit 调试。但这没有用。我似乎无法弄清楚这个问题的原因。我在表单的关键点添加了一些代码,将行号写入文本文件,这样我就可以看到它失败的地方,但似乎错误发生在那些记录的消息之前。如果我单击继续,消息会继续显示,如果我继续单击,它似乎确实在缓慢地执行代码,但需要多次单击才能出现相同的错误。

下面是MainForm_Load方法:

private void MainForm_Load(object sender, EventArgs e)
{
    backgroundWorker1.RunWorkerAsync(txtTerminal.Text);
    File.AppendAllText(ConfigurationManager.AppSettings["ErrorLog"],"Line:284" + Environment.NewLine);
}

您在 MainForm 中的 MainForm_Load 方法中生成了一个路径。

失败,结果变为 null。至少例外是这么说的..