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

Jackson Harper jackson at ximian.com
Tue May 31 05:46:22 EDT 2005


On Mon, 2005-05-30 at 10:31 +0200, Kornél Pál wrote:
> Hi,
> 
> Is there any official or unofficial but working way to determine what kind
> of CLI runtime environment is executing the assembly?

> 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.
> 

  As for your first reason, I think you are better off checking for the
runtime functionality on a case-by-case basis instead of saying:

	if (mono)
  		do some mono specific stuff
	if (msft)
  		do some msft specific stuff

it is usually better to do something along the lines of

	if (determine whether runtime supports a feature)
   		do feature specific stuff

a variation would be:

	try {
    		Feature = val;
	}  catch {
    		// On mono this throws an exception...
	}

as for your second point I agree that having the
runtime/platform/version in error reporting could be very useful. One
way of getting a version number on mono would be to pull the corlib
version number from System.Environment. This is stored in a variable
named mono_corlib_version that you could access via reflection. This
would obviously only work on mono. You can also grab the AssemblyProduct
or AssemblyCompany attributes from System.dll. On mono these are set to
different values then on msft. There aren't any guarantees the name will
stay the same though. Ultimately this will get pretty messy, forcing you
to probe different places for different features. Also this obviously
won't scale to new CLI runtimes, and as you are accessing private data
this could be broken by changes in the underlying runtimes.

Good luck!
Jackson






More information about the Mono-devel-list mailing list