Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Mono a subset of .NET?

Tags:

.net

mono

I know the converse is not true, but if my application works using Mono is it guaranteed to work if I switch to the real deal? If not, where can I find a list of caveats?

like image 909
Aillyn Avatar asked Aug 15 '10 13:08

Aillyn


People also ask

How does Mono work on Linux?

Mono implements the CLR on Linux, Mac, and other platforms. The Mono runtime (the CLR) is a native application written mostly in the C language and compiled down to machine language code for the computer system on which is designed to run.

What version of C# does mono use?

The Mono C# compiler is considered feature complete for C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0 and C# 6.0 (ECMA) and it has partial support for C# 7.


3 Answers

Both Mono and .NET are supersets of the ECMA/ISO CLI family of specifications. However, neither .NET nor Mono are subsets of the other. Both Mono and .NET add features on top of ECMA/ISO CLI, but while Mono implements many of .NET's additions, .NET does not implement any of Mono's additions.

Here's a few examples:

  • Mono has larger arrays. This is actually not an added feature to the ECMA/ISO CLI specification but an optional one: the specification says that array indices must be either 32 bit or 64 bit. .NET chose 32 bit but Mono chose 64, since arrays with 10 billion entries and more are quite common in supercomputing applications, where Mono has quite a strong market share. So, if your app has an array with several billions of entries, it will run just fine on Mono but won't work on .NET.
  • Mono has continuations built into the VM. These are important for game programming.
  • Mono has native SIMD support for parallel operations on arrays, which are mapped to native CPU SIMD instructions (MMX, SSE, VMX).
  • Mono has compiler-as-a-service, which Microsoft has been only vaguely talking about for some unspecified future version of .NET.
  • Mono has a lot of additional libraries, especially bindings to graphics libraries other than Windows Forms (wx.NET, Gtk#, Cocoa#, ...)

Note, however, that (except for the arrays), all of these are clearly distinguishible by their namespaces, since none of them live in the System or Microsoft namespaces.


EDIT: Actually, most of the above-mentioned extensions are explicitly designed to also work on .NET. For example, Mono.Simd also runs on .NET, but without the runtime support that the Mono VM has, it's unusably slow. (Basically, all the SIMD operations are implemented in C#, but the Mono compiler detects those calls and replaces them with their corresponding assembly instructions. That way, they work on .NET, but without the special treatment, they are significantly slower.) Also, the C# REPL is currently being re-implemented on top of Reflection.Emit (at the moment, it calls the Mono compiler directly), so that it will work on .NET in the future. Gtk# works just fine on Windows and .NET.

Only the Mono.Tasklet library cannot be implemented on .NET, since it requires VM-level support for continuations.

like image 189
Jörg W Mittag Avatar answered Oct 14 '22 19:10

Jörg W Mittag


No. Mono includes several alternative UI frameworks (Gtk#, wxWindows for .NET, etc).

If you only use Microsoft-defined classes, though, you should be fine.

like image 23
Stephen Cleary Avatar answered Oct 14 '22 18:10

Stephen Cleary


Mono is an implementation of the CLI standard, as is the CLR.

It includes many of the libraries you would find in the .NET BCL, but not any that are windows specific (WMI is one whole domain that comes to mind).

So long as you keep to features that are not windows specific, you should be fine.

The mono team have created a tool to check if your code should work on mono - MoMA, the Mono Migration Analyzer.

As far as using mono code with the Microsoft compilers, so long as you include the libraries you are using and are not doing any pInvokes on linux, you should be fine.

like image 40
Oded Avatar answered Oct 14 '22 17:10

Oded