public static IAssemblyCache GetAssemblyCacheInterface(string CLRVersionString, bool FetchRuntimeHost, out CCorRuntimeHost RuntimeHost) { IClrMetaHostPolicy clrMetaHostPolicy = null; RuntimeHost = null; GetClrMetaHostPolicy(ref _metaHostPolicyClsIdGuid, ref _metaHostPolicyGuid, out clrMetaHostPolicy); if (clrMetaHostPolicy == null) { return(null); } StringBuilder version = new StringBuilder("v", "v65535.65535.65535".Length); version.Append(CLRVersionString); int capacity = version.Capacity; int imageVersionLength = 0; int pdwConfigFlags = 0; IClrRuntimeInfo runtimeInfo = (IClrRuntimeInfo)clrMetaHostPolicy.GetRequestedRuntime(MetaHostPolicyFlags.MetaHostPolicyApplyUpgradePolicy, null, null, version, ref capacity, null, ref imageVersionLength, out pdwConfigFlags, _clrRuntimeInfoGuid); if (runtimeInfo == null) { return(null); } CoInitializeEEDelegate delegateForFunctionPointer = (CoInitializeEEDelegate)Marshal.GetDelegateForFunctionPointer(runtimeInfo.GetProcAddress("CoInitializeEE"), typeof(CoInitializeEEDelegate)); Marshal.ThrowExceptionForHR(delegateForFunctionPointer(0)); if (FetchRuntimeHost) { RuntimeHost = new CCorRuntimeHost(runtimeInfo); } CreateAssemblyCacheDelegate delegate3 = (CreateAssemblyCacheDelegate)Marshal.GetDelegateForFunctionPointer(runtimeInfo.GetProcAddress("CreateAssemblyCache"), typeof(CreateAssemblyCacheDelegate)); IAssemblyCache ppAsmCache = null; Marshal.ThrowExceptionForHR(delegate3(out ppAsmCache, 0)); return(ppAsmCache); }
public static IClrRuntimeInfo GetRuntime(IEnumUnknown runtimes, String version) { Object[] temparr = new Object[3]; UInt32 fetchedNum; do { runtimes.Next(Convert.ToUInt32(temparr.Length), temparr, out fetchedNum); for (Int32 i = 0; i < fetchedNum; i++) { IClrRuntimeInfo t = (IClrRuntimeInfo)temparr[i]; // version not specified we return the first one if (String.IsNullOrEmpty(version)) { return(t); } // initialize buffer for the runtime version string StringBuilder sb = new StringBuilder(16); UInt32 len = Convert.ToUInt32(sb.Capacity); t.GetVersionString(sb, ref len); "version: {0}".info(sb.str()); if (sb.ToString().StartsWith(version, StringComparison.Ordinal)) { return(t); } } } while (fetchedNum == temparr.Length); return(null); }
internal static IClrStrongName GetInstance() { Guid metaHostClsid = new Guid(unchecked ((int)0x9280188D), 0xE8E, 0x4867, 0xB3, 0xC, 0x7F, 0xA8, 0x38, 0x84, 0xE8, 0xDE); Guid metaHostGuid = new Guid(unchecked ((int)0xD332DB9E), unchecked ((short)0xB9B3), 0x4125, 0x82, 0x07, 0xA1, 0x48, 0x84, 0xF5, 0x32, 0x16); Guid clrStrongNameClsid = new Guid(unchecked ((int)0xB79B0ACD), unchecked ((short)0xF5CD), 0x409b, 0xB5, 0xA5, 0xA1, 0x62, 0x44, 0x61, 0x0B, 0x92); Guid clrRuntimeInfoGuid = new Guid(unchecked ((int)0xBD39D1D2), unchecked ((short)0xBA2F), 0x486A, 0x89, 0xB0, 0xB4, 0xB0, 0xCB, 0x46, 0x68, 0x91); Guid clrStrongNameGuid = new Guid(unchecked ((int)0x9FD93CCF), 0x3280, 0x4391, 0xB3, 0xA9, 0x96, 0xE1, 0xCD, 0xE7, 0x7C, 0x8D); IClrMetaHost metaHost = (IClrMetaHost)nCreateInterface(metaHostClsid, metaHostGuid); IClrRuntimeInfo runtime = (IClrRuntimeInfo)metaHost.GetRuntime(GetRuntimeVersion(), clrRuntimeInfoGuid); return((IClrStrongName)runtime.GetInterface(clrStrongNameClsid, clrStrongNameGuid)); }
public static bool isRuntime(this Process process, string version) { if (process.isNull()) { "in process.isRuntime , process value was null".error(); return(false); } Guid clsid = new Guid("9280188D-0E8E-4867-B30C-7FA83884E8DE"); Guid riid = new Guid("D332DB9E-B9B3-4125-8207-A14884F53216"); var metahost = (IClrMetaHost)_NativeMethods.nCLRCreateInstance(clsid, riid); IEnumUnknown runtimes = metahost.EnumerateLoadedRuntimes(process.Handle); IClrRuntimeInfo runtime = _NativeMethods.GetRuntime(runtimes, version); //IClrRuntimeInfo runtime = _NativeMethods.GetRuntime(runtimes, "v2.0"); return(runtime.notNull()); }
bool IsCLRVersionInstalled(Version clrVersion) { object pCLRMetaHost; bool isRuntimeVersionDetermined = false; if (SafeNativeMethods.ERROR_SUCCESS == SafeNativeMethods.CLRCreateInstance(CLSID_CLRMetaHost, typeof(IClrMetaHost).GUID, out pCLRMetaHost)) { IClrMetaHost metaHost = (IClrMetaHost)pCLRMetaHost; IEnumUnknown enumUnknownPtr; enumUnknownPtr = metaHost.EnumerateInstalledRuntimes(); object[] pUnk = new object[1]; int pceltFetched; while (SafeNativeMethods.ERROR_SUCCESS == enumUnknownPtr.Next(1, pUnk, out pceltFetched) && !isRuntimeVersionDetermined) { int bufferSize = 256; StringBuilder builder = new StringBuilder(256); IClrRuntimeInfo runtimeInfo = (IClrRuntimeInfo)pUnk[0]; runtimeInfo.GetVersionString(builder, ref bufferSize); Version installedClrVersion; if (TryGetVersionFromString(builder, out installedClrVersion)) { if (clrVersion.Major == installedClrVersion.Major && clrVersion.Minor == installedClrVersion.Minor) { isRuntimeVersionDetermined = true; } } } } return(isRuntimeVersionDetermined); }
/// <summary> /// Constructor that wraps an ICLRRuntimeInfo (used internally) /// </summary> internal ClrRuntimeInfo(IClrRuntimeInfo info) { System.Diagnostics.Debug.Assert(info != null); _RuntimeInfo = info; }