tags:

views:

401

answers:

5

I wanted to know what i shouldn't do in code that will prevent my C# app from running on mac.

+3  A: 

In general you shouldn't use anything from the Microsoft.* namespaces, no PInvoke (DllImport in C#) and UI might be problematic as well.

Further information on Mono compatibility is contained in the Mono Guide Porting Winforms Applications. Existing applications can be checked for compatibility using the Migration Analyzer tool.

UPDATE: PInvoke actually works in Mono, but if you want to have it working cross-platform you must provide a native shared library with the same interface for each platform (i.e. Win API most likely will not work).

0xA3
A: 

I'm not sure if it is possible with mono, but WIN32 API calls will definitly not work ;)

Sebastian Sedlak
A: 

You will, at the very least, want to try and avoid using Windows Forms, since that is just a paper-thin layer on top of the Windows native UI.

Mono emulates it somewhat with help from WINE, but I wouldn't trust that. Mono did this a while ago but the effort was abandoned. See WinForms on Mono for more information. Thanks jpobst.

Try using GTK# or Qt# (although I'm not too sure the latter one actually exists) for cross platform support. You might also consider using Java with SWT or even Swing instead of C#, but that will probably not be an option you're willing to consider.

Using anything related to P/Invoke is probably also a bad idea, since that invokes native code which will probably not be portable (unless you write it yourself, then you can choose to make it portable).

Gerco Dries
How can i build GUI in MSVS for GTK or QT?
acidzombie24
You can start by looking at this tutorial: http://mono-project.com/GtkSharpBeginnersGuideUsing Qt in .NET is a little more involved, but you can find a walkthrough here: http://doc.trolltech.com/4.2/activeqt-dotnet.html
Gerco Dries
Mono using WINE is incorrect. Mono's Winforms implementation is completely managed, using System.Drawing to draw all the controls.
jpobst
+3  A: 

Mono's Application Portability guide is a good reference.

jpobst
+1  A: 

In addition to divo's recommendations, I would recommend the Mono Migration Analyzer (MoMA) tool: "The Mono Migration Analyzer (MoMA) tool helps you identify issues you may have when porting your .Net application to Mono"

Also, I would keep an eye on Miguel de Icaza's blog, and the Mono Project website.

In his presentation for the Boston.NET Users Group this month, he showed a preview of a Visual Studio plugin that launches your app on Mono using a VM! This lets you test compatibility during the development process.

I believe their goal was to release it at TechEd 2009, so look for an update over the next month or so.

Ben Anderson