[Mono-list] Determine the name and/or kind of CLI runtime environment

Kornél Pál kornelpal at hotmail.com
Mon May 30 15:56:23 EDT 2005


Hi,

>From: "Todd Berman"
> The real question is why?

I have written in my first message in the thread, but it wasn't in the
message you replied, so I copy it:

>They have different interfaces to low level runtime functionality and it is
>good if an error report contains the name of the CLI runtime as well.

In error reporting it is very important to know the name of the runtime.

> It seems like in general, doing capability based testing gets you futher
> than checking which runtime you are on. Just isolate easy tests that can
> determine if the needed functionality is there, and use those.

You are absolutely right regarding this topic, the application itself has to
use the functionality depending on it's availability and not the name of the
runtime, but if more than one runtimes are installed you can control all of
them.

For example on Windows you can access mscoree.dll from a managed application
running on Mono and a you can also have Mono and .NET Framework runtime
loaded into the same process.

>From: "Robert Jordan"
> You may try to instantiate a type that only exists
> on Mono (i.e. one from the Mono.* namespaces). However, most
> of those types might run with MSFT runtime as well ...

Thank you for your answer, this gave me some ideas.

> Another way might be to call some unimplemented
> System.Runtime.InteropServices.Marshal methods.
> That's what I'm doing.

But I don't recommend your current practicle. The main cause is that these
methods will be implemeneted in the near or distant future.

I think the following code is a good solution:

Assembly mscorlibAssembly = typeof(object).Assembly;
string runtimeName;
if (mscorlibAssembly.GetType("Microsoft.Win32.Fusion") != null)
 runtimeName = "Microsoft .NET Framework";
else if (mscorlibAssembly.GetType("Mono.Runtime") != null)
 runtimeName = "Mono";
else if (mscorlibAssembly.GetType("Platform.TaskMethods") != null)
 runtimeName = "DotGNU Portable.NET";
else
 runtimeName = "Unknown Runtime";
Console.WriteLine(String.Format("Runtime: {0} {1}", runtimeName,
Environment.Version.ToString()));

All of these types are from mscorlib.dll and it is the only assembly that is
guaranted to exist and be specific on each platforms.
All of them are internal classes so it is very unlikely to be copied ever.
"Microsoft.Win32.Fusion" is OK, it exists in 1.0, 1.1 and 2.0 as well and
Fusion is the code name of the GAC manager, so it's Microsoft specific.
"Platform.TaskMethods" is OK, it exists since the early releases and is
specific to Portable.NET.

My only problem is "Mono.Runtime" is seems not to been always there.
Could anyone suggest a better class name in mscorlib.dll?

If we can found an internal, Mono specific class in mscorlib.dll that is
included almost every release we should document that the class shouldn't be
removed to provide a way to detect Mono.

Kornél



More information about the Mono-list mailing list