Export (0) Print
Expand All

RuntimeEnvironment Class

Provides a collection of static methods that return information about the common language runtime environment.

System.Object
  System.Runtime.InteropServices.RuntimeEnvironment

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
public class RuntimeEnvironment

The RuntimeEnvironment type exposes the following members.

  NameDescription
Public methodRuntimeEnvironment Obsolete. Initializes a new instance of the RuntimeEnvironment class.
Top

  NameDescription
Public propertyStatic memberSystemConfigurationFileGets the path to the system configuration file.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberFromGlobalAccessCacheTests whether the specified assembly is loaded in the global assembly cache.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodStatic memberGetRuntimeDirectoryReturns the directory where the common language runtime is installed.
Public methodStatic memberGetRuntimeInterfaceAsIntPtrReturns the specified interface on the specified class.
Public methodStatic memberGetRuntimeInterfaceAsObjectReturns an instance of a type that represents a COM object by a pointer to its IUnknown interface.
Public methodStatic memberGetSystemVersionGets the version number of the common language runtime that is running the current process.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

This example shows how to call many of the methods defined by the RuntimeEnvironment class.

using System;
using System.Reflection;
using System.Runtime.InteropServices;

public sealed class App 
{
    static void Main() 
    {       
        // Show whether the EXE assembly was loaded from the GAC or from a private subdirectory.
        Assembly assem = typeof(App).Assembly;
        Console.WriteLine("Did the {0} assembly load from the GAC? {1}",
           assem, RuntimeEnvironment.FromGlobalAccessCache(assem));

        // Show the path where the CLR was loaded from.
        Console.WriteLine("Runtime directory: {0}", RuntimeEnvironment.GetRuntimeDirectory());

        // Show the CLR's version number.
        Console.WriteLine("System version: {0}", RuntimeEnvironment.GetSystemVersion());

        // Show the path of the machine's configuration file.
        Console.WriteLine("System configuration file: {0}", RuntimeEnvironment.SystemConfigurationFile);
    }
}

// This code produces the following output. 
// 
// Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 
// assembly load from the GAC? False 
// Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\ 
// System version: v2.0.40607 
// System configuration file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\ 
// machine.config

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft