Example #1
0
        public static NativeMethods.IAssemblyCache GetAssemblyCacheInterface(string CLRVersionString, bool FetchRuntimeHost, out NativeMethods.CCorRuntimeHost RuntimeHost)
        {
            NativeMethods.IClrMetaHostPolicy ClrMetaHostPolicy = (NativeMethods.IClrMetaHostPolicy)null;

            RuntimeHost = (NativeMethods.CCorRuntimeHost)null;
            NativeMethods.GetClrMetaHostPolicy(ref NativeMethods._metaHostPolicyClsIdGuid, ref NativeMethods._metaHostPolicyGuid, out ClrMetaHostPolicy);
            if (ClrMetaHostPolicy == null)
            {
                return((NativeMethods.IAssemblyCache)null);
            }
            StringBuilder version = new StringBuilder("v", "v65535.65535.65535".Length);

            version.Append(CLRVersionString);
            int versionLength      = version.Capacity;
            int imageVersionLength = 0;
            int pdwConfigFlags     = 0;

            NativeMethods.IClrRuntimeInfo requestedRuntime = (NativeMethods.IClrRuntimeInfo)ClrMetaHostPolicy.GetRequestedRuntime(NativeMethods.MetaHostPolicyFlags.MetaHostPolicyApplyUpgradePolicy, (string)null, (IStream)null, version, out versionLength, (StringBuilder)null, out imageVersionLength, out pdwConfigFlags, NativeMethods._clrRuntimeInfoGuid);
            if (requestedRuntime == null)
            {
                return((NativeMethods.IAssemblyCache)null);
            }
            Marshal.ThrowExceptionForHR(((NativeMethods.CoInitializeEEDelegate)Marshal.GetDelegateForFunctionPointer(requestedRuntime.GetProcAddress("CoInitializeEE"), typeof(NativeMethods.CoInitializeEEDelegate)))(0U));
            if (FetchRuntimeHost)
            {
                RuntimeHost = new NativeMethods.CCorRuntimeHost(requestedRuntime);
            }
            NativeMethods.CreateAssemblyCacheDelegate forFunctionPointer = (NativeMethods.CreateAssemblyCacheDelegate)Marshal.GetDelegateForFunctionPointer(requestedRuntime.GetProcAddress("CreateAssemblyCache"), typeof(NativeMethods.CreateAssemblyCacheDelegate));
            NativeMethods.IAssemblyCache ppAsmCache = (NativeMethods.IAssemblyCache)null;
            Marshal.ThrowExceptionForHR(forFunctionPointer(out ppAsmCache, 0U));
            return(ppAsmCache);
        }
Example #2
0
            public CCorRuntimeHost(NativeMethods.IClrRuntimeInfo RuntimeInfo)
            {
                StringBuilder buffer = new StringBuilder(260);

                int bufferLength = buffer.Capacity;

                RuntimeInfo.GetVersionString(buffer, out bufferLength);
                this.ClrRuntimeInfoVersion = buffer.ToString();
                Logger.AddMethodCall("CCorRuntimeHost.ctor called with IClrRuntimeInfo version " + this.ClrRuntimeInfoVersion, DateTime.Now);
                this.RuntimeHostInstance = (NativeMethods.ICorRuntimeHost)RuntimeInfo.GetInterface(NativeMethods._corRuntimeHostClsIdGuid, NativeMethods._corRuntimeHostInterfaceIdGuid);
            }