2

我有一个在 Windows 7(64 位)上编写的程序,可以在我的计算机上正确编译和运行。

但在其他计算机上(特别是在 Windows 8(64 位)上)该程序无法运行。当我尝试运行它时,它说我的程序已停止工作,它崩溃了。

我应该补充一点,两台计算机都安装了 4.5 版的 .Net。

但是,如果我删除了添加到表单中的所有组件(我使用的是 Visual Studio 2012 Express),它运行得很好。但我必须删除所有组件。只删除其中一些是行不通的。

有没有人听说过这种情况?

4

1 回答 1

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);
    }
于 2013-09-05T20:09:38.680 回答