Running .NET 4 application with Mono

2019-03-14 19:10发布

问题:

I'm trying to run a .NET exe on a Ubuntu machine (I installed the package mono-complete), so far with no luck. The application is compiled with Visual C# Express 2010 under .NET 4 (Client Profile).

I try executing the program with the following command:

mono application.exe

However, I get the following error:

WARNING: The runtime version supported by this application is unavailable. Using default runtime: v1.1.4322

** (application.exe:5586): WARNING **: Missing method System.Windows.Forms.Application::SetCompatibleTextRenderingDefault(bool) in assembly /usr/lib/mono/gac/System.Windows.Forms/1.0.5000.0__b77a5c561934e089/System.Windows.Forms.dll, referenced in assembly /media/disk/application.exe

Unhandled Exception: System.MissingMethodException: Method not found: 'System.Windows.Forms.Application.SetCompatibleTextRenderingDefault'.

It's suppose to be using .NET 4, not 1, but I don't know how to set it. I tried

mono --runtime=4.0.30319.1 application.exe

But that didn't work either.

Any help would be appreciated.

回答1:

Sounds like you're experiencing this bug:

My Doc's Got No Nodes: .net 4 Client Profile on Mono 2.8

That is assuming you installed > Mono 2.8 (which was the first release to support .NET 4.0). If not, you should install a more recent Mono package.

The other thing to keep in mind is that Mono doesn't support the entirety of WinForms. Unless you developed your application with Mono in mind, there's a good chance you'll find that something you used isn't supported.



回答2:

I suspect the exception is because the method System.Windows.Forms.Application.SetCompatibleTextRenderingDefault hasn't been implemented. Have you ran the tool through the Mono Migration Analyzer (MoMA), should help in knowing whether your application is compatible with mono. From that point you can possibly workaround the problem, maybe even incorporating the missing method in your code.



回答3:

Current mono-complete package (even on Ubuntu Natty) uses mono 2.6.7 which doesn't support .NET 4.0 API. You'll have to build newest version of mono, which is the best way to get a chance of using 4.0 API. "Complete" support of .NET 4.0 is however planned in mono 3.0.



回答4:

Install Monodevelop and just right click on the example.csprj that is a C#.NET project in linux and click on Monodevelop.