我有一个带有 vs2010 的 windows 7 x64 桌面和一个带有 mono 和 monodevelop 的 linux 虚拟盒安装。我用 vs2010 编译以下程序并在 linux 虚拟机中运行它,它失败并出现看似无法捕获的 FileNotFoundException。如果我在虚拟机中编译并在windows中运行它,效果很好。
问题似乎是当无法加载 dll 时,在 Main() 之前,mono 抛出了一个无法捕获的异常。有没有办法重组我的程序或强制单声道,以便我可以捕捉到这个异常?
我正在尝试根据运行时可用的内容编写一个在 WPF 或 GTK 中具有接口的单个程序。
using System;
#if __MonoCS__
using Gtk;
#else
using System.Windows;
#endif
using System.IO;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
namespace Test {
public static class Program {
[STAThread]
public static void Main() {
try {
Main2();
} catch (FileNotFoundException e) {
Console.WriteLine("Caught FileNotFoundException");
Console.WriteLine("FileName = {0}", e.FileName);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Main2() {
#if __MonoCS__
Application.Init();
#else
Window w = new Window();
#endif
}
}
}