[Mono-list] Detecting mono version

Jonathan Pryor jonpryor at vt.edu
Sun Feb 24 08:34:14 EST 2008


On Wed, 2008-02-20 at 13:32 +0100, Erik Renes wrote:
> Hi All, 
> 
> I am wondering if there is a way to detect the mono runtime version. 
> I am trying to detect the version to be able to gracefully handle the known
> issues in windows.forms implementation (my app has serious issues on 1.2.3,
> but works fine on 1.2.4 upwards). 

Mono.Runtime.GetDisplayName() is commented as:

    // Should not be removed intended for external use
    // Safe to be called using reflection
    // Format is undefined only for use as a string for reporting

It should be safe to rely on this method, though not necessarily to rely
on the semantics/format of this method.

Mono.Runtime can't be public because it's in mscorlib.dll, and we need
to provide the same public API as .NET's mscorlib.dll (otherwise you
could compile against Mono and the resulting app wouldn't run on .NET).

> My current code (proof of concept): 
>   Type t = Type.GetType("Mono.Runtime");
>   MethodInfo mi = t.GetMethod("GetDisplayName", BindingFlags.NonPublic |
> BindingFlags.Static );
>   string s = (string)mi.Invoke(null, null);
>   if (mi!= null)
>     Console.WriteLine(s);

You should check that `t' is not null before using it, as it will be
null when running on .NET.  Otherwise, that looks correct.

 - Jon




More information about the Mono-list mailing list