Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell my code is running on Mono? [duplicate]

Tags:

.net

mono

Possible Duplicate:
How to detect which .NET runtime is being used (MS vs. Mono)?

In .net how dow I tell if my code is running on Mono?

like image 461
Simon Avatar asked Aug 16 '11 11:08

Simon


2 Answers

From the Mono FAQ:

http://www.mono-project.com/FAQ:_Technical

Below is directly from that link:

How can I detect if am running in Mono?

Having code that depends on the underlying runtime is considered to be bad coding style, but sometimes such code is necessary to work around runtime bugs. The supported way of detecting Mono is:

using System;

class Program {
    static void Main ()
    {
        Type t = Type.GetType ("Mono.Runtime");
        if (t != null)
             Console.WriteLine ("You are running with the Mono VM");
        else
             Console.WriteLine ("You are running something else");
    }
}

Any other hack, such as checking the underlying type of System.Int32 or of other corlib types, is doomed to fail in the future.

Long and short of it, just don't.

like image 140
Adam Houldsworth Avatar answered Nov 14 '22 00:11

Adam Houldsworth


From mono porting guide:

public static bool IsRunningOnMono ()
{
  return Type.GetType ("Mono.Runtime") != null;
}
like image 11
Matten Avatar answered Nov 13 '22 22:11

Matten