程序在Win 7上运行,但在Win 8上运行

Ele*_*ec0 2 c# windows windows-7 windows-8

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

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

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

但是,如果我删除了我在表单上添加的所有组件(我使用的是Visual Studio 2012 Express),它运行得很好.但我必须删除所有组件.仅删除其中一些不起作用.

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

Ele*_*ec0 5

Thanks to Hans, I hadn't heard of the AppDomain.CurrentDomain.Unhandled exception before.

My actual problem was that I didn't have the VisualBasic things installed on the Windows 8 computer, and I was trying to use them. Removing the references of that from my program fixed the program.

The actual code I used to find the problem (In 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);
    }
Run Code Online (Sandbox Code Playgroud)