I have a windows 7 x64 desktop with vs2010 and a virtual box installation of linux with mono and monodevelop. I compile the following program with vs2010 and run it in the linux virtual machine and it fails with a seemingly uncatchable FileNotFoundException. If I compile it in the virtual machine and run it in windows, it works great.
The problem seems to be that an uncatchable exception is tossed by mono before Main() when it is impossible to load a dll. Is there a way to restructure my program or coerce mono such that I can catch this exception?
I am trying to write a single program that has an interface in either WPF or GTK according to what is available at runtime.
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
}
}
}