예제 #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);
        }
예제 #2
0
        public static bool VerifyCLRVersionInfo(Version v, string procArch)
        {
            bool flag = true;

            NativeMethods.IClrMetaHostPolicy ClrMetaHostPolicy = (NativeMethods.IClrMetaHostPolicy)null;
            NativeMethods.GetClrMetaHostPolicy(ref NativeMethods._metaHostPolicyClsIdGuid, ref NativeMethods._metaHostPolicyGuid, out ClrMetaHostPolicy);
            if (ClrMetaHostPolicy == null)
            {
                return(false);
            }
            string        str     = v.ToString(3);
            StringBuilder version = new StringBuilder("v", "v65535.65535.65535".Length);

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

            try
            {
                if ((NativeMethods.IClrRuntimeInfo)ClrMetaHostPolicy.GetRequestedRuntime(NativeMethods.MetaHostPolicyFlags.MetaHostPolicyApplyUpgradePolicy, (string)null, (IStream)null, version, out versionLength, (StringBuilder)null, out imageVersionLength, out pdwConfigFlags, NativeMethods._clrRuntimeInfoGuid) == null)
                {
                    flag = false;
                }
            }
            catch (COMException ex)
            {
                flag = false;
                if (ex.ErrorCode != -2146232576)
                {
                    throw;
                }
            }
            return(flag);
        }
예제 #3
0
 private static extern void GetClrMetaHostPolicy(ref Guid clsid, ref Guid iid, [MarshalAs(UnmanagedType.Interface)] out NativeMethods.IClrMetaHostPolicy ClrMetaHostPolicy);