System.Diagnostics.SymbolStore.SymBinder.GetReader C# (CSharp) Method

GetReader() public method

public GetReader ( int importer, string filename, string searchPath ) : ISymbolReader
importer int
filename string
searchPath string
return ISymbolReader
        public ISymbolReader GetReader(
            int importer, 
            string filename,
            string searchPath)
        {

            IntPtr Reader;

            // Demand the permission to access unmanaged code. We do this since we are casting an int to a COM interface, and
            // this can be used improperly.
            (new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)).Demand();

            int hr;
            COMException Exception;

            hr = SymBinder_GetReaderForFile(m_Binder, importer, filename, searchPath, out Reader);
            if (hr < 0)
            {
                Exception = new COMException("Call to GetReaderForFile failed.", hr);
                throw Exception;
            }

            SymReader symReader = new SymReader(Reader);
            return symReader;
        }
    }

Usage Example

Esempio n. 1
0
        public static ISymbolReader GetSymbolReaderForFile(
            System.Diagnostics.SymbolStore.SymBinder binder, string pathModule, string searchPath)
        {
            // Guids for imported metadata interfaces.
            Guid dispenserClassID = new Guid(0xe5cb7a31, 0x7512, 0x11d2, 0x89,
                                             0xce, 0x00, 0x80, 0xc7, 0x92, 0xe5, 0xd8); // CLSID_CorMetaDataDispenser
            Guid dispenserIID = new Guid(0x809c652e, 0x7396, 0x11d2, 0x97, 0x71,
                                         0x00, 0xa0, 0xc9, 0xb4, 0xd5, 0x0c);           // IID_IMetaDataDispenser
            Guid importerIID = new Guid(0x7dac8207, 0xd3ae, 0x4c75, 0x9b, 0x67,
                                        0x92, 0x80, 0x1a, 0x49, 0x7d, 0x44);            // IID_IMetaDataImport

            // First create the Metadata dispenser.
            object objDispenser;

            NativeMethods.CoCreateInstance(ref dispenserClassID, null, 1,
                                           ref dispenserIID, out objDispenser);

            // Now open an Importer on the given filename. We'll end up passing this importer
            // straight through to the Binder.
            object             objImporter = null;
            IMetaDataDispenser dispenser   = (IMetaDataDispenser)objDispenser;

            try
            {
                dispenser.OpenScope(pathModule, 0, ref importerIID, out objImporter);
            }
            catch
            {
                Console.WriteLine(" ERROR: Failed dispenser.OpenScope() - perhaps this app needs to be compiled in x86?");
                return(null);
            }

            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(IMetadataImport));

                reader = binder.GetReader(importerPtr, pathModule, searchPath);
            }
            finally
            {
                if (importerPtr != IntPtr.Zero)
                {
                    Marshal.Release(importerPtr);
                }
            }
            return(reader);
        }
All Usage Examples Of System.Diagnostics.SymbolStore.SymBinder::GetReader