我有一个我在Windows 7(64位)上编写的程序,可以在我的计算机上正确编译和运行。
但在其他计算机上(特别是在Windows 8(64位)上),该程序无法运行。当我尝试运行它时,它说我的程序已停止工作,它崩溃了。
我应该补充一下,两台计算机都安装了.Net版本4.5。
但是,如果我删除了我在表单上添加的所有组件(我使用的是Visual Studio 2012 Express),它运行得很好。但我必须删除所有组件。只删除其中一些不起作用。
有没有人听说过这件事?
答案 0 :(得分:5)
感谢Hans,我之前没有听说过AppDomain.CurrentDomain.Unhandled异常。
我的实际问题是我没有在Windows 8计算机上安装VisualBasic,我试图使用它们。从我的程序中删除它的引用修复了程序。
我用来查找问题的实际代码(在Program.cs中):
static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
(...)
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
MessageBox.Show("Handler caught: " + e.Message + "\nRuntime terminating: " + args.IsTerminating);
}