System.Diagnostics.StackTraceSymbols.TryOpenReaderForInMemoryPdb C# (CSharp) Method

TryOpenReaderForInMemoryPdb() private static method

private static TryOpenReaderForInMemoryPdb ( IntPtr inMemoryPdbAddress, int inMemoryPdbSize ) : System.Reflection.Metadata.MetadataReaderProvider
inMemoryPdbAddress IntPtr
inMemoryPdbSize int
return System.Reflection.Metadata.MetadataReaderProvider
        private unsafe static MetadataReaderProvider TryOpenReaderForInMemoryPdb(IntPtr inMemoryPdbAddress, int inMemoryPdbSize)
        {
            Debug.Assert(inMemoryPdbAddress != IntPtr.Zero);

            // quick check to avoid throwing exceptions below in common cases:
            const uint ManagedMetadataSignature = 0x424A5342;
            if (inMemoryPdbSize < sizeof(uint) || *(uint*)inMemoryPdbAddress != ManagedMetadataSignature)
            {
                // not a Portable PDB
                return null;
            }

            var provider = MetadataReaderProvider.FromMetadataImage((byte*)inMemoryPdbAddress, inMemoryPdbSize);
            try
            {
                // may throw if the metadata is invalid
                provider.GetMetadataReader();
                return provider;
            }
            catch (BadImageFormatException)
            {
                provider.Dispose();
                return null;
            }
        }