SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

SharpDevelop 2.0 and Mono

As of revision 568, available from the repository, SharpDevelop 2.0 supports C# projects targeting Mono 1.1.9.2.

Prerequisites

  • Mono 1.1.9.2 is installed.
  • The Mono bin folder has been added to the "Path" environment variable (Control Panel | System | Advanced | Environment Variables).

Targeting Mono

To target Mono, open the project's "Compiling" options (Project | Project Options | Compiling) and select either "Mono 1.1" or "Mono 2.0" from the "Target Framework" drop down list.

With "Mono 1.1" selected the Mcs compiler will be used.  With "Mono 2.0" selected the Gmcs compiler will be used.

Running your Application

After you have compiled your code using Mcs or Gmcs you can then run your application under Microsoft's .NET Framework or under Mono's Framework. If you want to run it under Microsoft's .NET Framework then you can use either of the menu options "Debug | Run" or "Debug | Run without debugger" as you would with a normal application created using SharpDevelop. You will need to make sure all the Mono specific assembly references (e.g. glib-sharp) have "Local Copy" set to "true", otherwise the Microsoft .NET Framework will be unable to find them. If you want to run your application under Mono's Framework instead follow the instructions in the next section.

Running under Mono

To configure your application to run under Mono's Framework, open the project's "Debug" options (Project | Project Options | Debug), switch the "Start Action" to "Start external program" and enter the path to the Mono executable, and finally set the "Command line arguments" to "${TargetPath}". If the path to your application's executable contains spaces put double quotes around the ${TargetPath} string.

To run your application under Mono, select the menu option Debug | Run without debugger.  You cannot use the SharpDevelop debugger to debug or run your Mono application.

Common Problems

Mcs/Gmcs exiting with code -1

If you are seeing errors such as:

"Mcs.exe" exited with code -1
Failed to execute compiler: -1: "C:\Program Files\Mono\bin\Mcs.bat"

This is usually because Mono cannot convert the command line into Unicode.  To fix this create a environment variable called MONO_EXTERNAL_ENCODINGS and set it to be "default_locale" without the quotes.

From the Mono man page:

MONO_EXTERNAL_ENCODINGS

If set, contains a colon-separated list of text encodings to try when turning externally-generated text (e.g. command-line arguments or filenames) into Unicode. The encoding names come from the list provided by iconv, and the special case "default_locale" which refers to the current locale's default encoding.

When reading externally-generated text strings UTF-8 is tried first, and then this list is tried in order with the first successful conversion ending the  search. When writing external text (e.g. new filenames or arguments to new processes) the first item in this list is used, or UTF-8 if the environment variable is not set.


[UPDATE 6th March, 2006]

Added MONO_EXTERNAL_ENCODINGS fix for the Mcs/Gmcs compiler failing with error code -1.  Thanks to Luis Segura for finding this solution.

[UPDATE 10th April, 2006]

Added some information about running under Microsoft's .NET Framework versus running under Mono. Added a note about putting double quotes around ${TargetPath} if the path to the executable being run under Mono contains spaces.
Published Okt 12 2005, 11:16 PM by MattWard
Filed under:

Comments

 

Matt Ward said:

In revision 983 SharpDevelop2 has support for Mono's GAC.  It also includes new Gtk# and Glade#...
Januar 10, 2006 3:09 PM
 

Mono and Sharpdevelop - A baby step at S H V E L M U R . C O M said:

Dezember 24, 2006 3:04 PM
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.