예제 #1
0
        // This private function provides implementation for the two public versions.
        // searchPath is a semicolon-delimited list of paths on which to search for pathModule.
        // If searchPath is null, pathModule must be a full path to the assembly.
        private static ISymbolReader GetReaderForFile(SymbolBinder binder, string pathModule, string searchPath)
        {
            // First create the Metadata dispenser.
            object objDispenser;
            // OLD:
            //NativeMethods.CoCreateInstance(ref dispenserClassID, null, 1, ref dispenserIID, out objDispenser);
            // NEW:
            // Source: https://social.msdn.microsoft.com/Forums/en-US/3a0a48bf-a308-45c7-8dcc-f85eaf1d32e5
            ICLRMetaHostPrivate metaHost = (ICLRMetaHostPrivate)NativeMethods.CLRCreateInstance(metaHostClassID, metaHostIID);
            object objRuntime;

            metaHost.GetRuntime("v4.0.30319", ref runtimeInfoIID, out objRuntime);
            IICLRRuntimeInfoPrivate runtime = (IICLRRuntimeInfoPrivate)objRuntime;

            runtime.GetInterface(ref dispenserClassID, ref dispenserExIID, out objDispenser);

            IMetadataDispenserPrivate dispenser = (IMetadataDispenserPrivate)objDispenser;

            // Now open an Importer on the given filename. We'll end up passing this importer straight
            // through to the Binder.
            object objImporter;

            dispenser.OpenScope(pathModule, OPEN_READ, ref importerIID, out objImporter);

            IntPtr        importerPtr = IntPtr.Zero;
            ISymbolReader reader;

            try
            {
                // This will manually AddRef the underlying object, so we need to be very careful to Release it.
                importerPtr = Marshal.GetComInterfaceForObject(objImporter, typeof(IMetadataImportPrivateComVisible));

                reader = binder.GetReader(importerPtr, pathModule, searchPath);
            }
            finally
            {
                if (importerPtr != IntPtr.Zero)
                {
                    Marshal.Release(importerPtr);
                }
            }
            return(reader);
        }
예제 #2
0
        // This private function provides implementation for the two public versions.
        // searchPath is a semicolon-delimited list of paths on which to search for pathModule.
        // If searchPath is null, pathModule must be a full path to the assembly.
        private static ISymbolReader GetReaderForFile(SymbolBinder binder, string pathModule, string searchPath)
        {
            // First create the Metadata dispenser.
            object objDispenser;
            // OLD:
            //NativeMethods.CoCreateInstance(ref dispenserClassID, null, 1, ref dispenserIID, out objDispenser);
            // NEW:
            // Source: https://social.msdn.microsoft.com/Forums/en-US/3a0a48bf-a308-45c7-8dcc-f85eaf1d32e5
            ICLRMetaHostPrivate metaHost = (ICLRMetaHostPrivate)NativeMethods.CLRCreateInstance(metaHostClassID, metaHostIID);
            object objRuntime;
            metaHost.GetRuntime("v4.0.30319", ref runtimeInfoIID, out objRuntime);
            IICLRRuntimeInfoPrivate runtime = (IICLRRuntimeInfoPrivate)objRuntime;
            runtime.GetInterface(ref dispenserClassID, ref dispenserExIID, out objDispenser);

            IMetadataDispenserPrivate dispenser = (IMetadataDispenserPrivate)objDispenser;

            // Now open an Importer on the given filename. We'll end up passing this importer straight
            // through to the Binder.
            object objImporter;
            dispenser.OpenScope(pathModule, OPEN_READ, ref importerIID, out objImporter);

            IntPtr importerPtr = IntPtr.Zero;
            ISymbolReader reader;
            try
            {
                // This will manually AddRef the underlying object, so we need to be very careful to Release it.
                importerPtr = Marshal.GetComInterfaceForObject(objImporter, typeof(IMetadataImportPrivateComVisible));

                reader = binder.GetReader(importerPtr, pathModule, searchPath);
            }
            finally
            {
                if (importerPtr != IntPtr.Zero)
                {
                    Marshal.Release(importerPtr);
                }
            }
            return reader;
        }