Remove faulty assert from MethodDebugInformation (#1662)
authorStephen Toub <stoub@microsoft.com>
Tue, 14 Jan 2020 02:47:30 +0000 (21:47 -0500)
committerGitHub <noreply@github.com>
Tue, 14 Jan 2020 02:47:30 +0000 (21:47 -0500)
* Remove faulty assert from MethodDebugInformation

* Update MetadataReaderTests.cs

src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/PortablePdb/MethodDebugInformation.cs
src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderTests.cs

index e51b4f4..5adf6ce 100644 (file)
@@ -22,7 +22,6 @@ namespace System.Reflection.Metadata
         internal MethodDebugInformation(MetadataReader reader, MethodDebugInformationHandle handle)
         {
             Debug.Assert(reader != null);
-            Debug.Assert(!handle.IsNil);
 
             _reader = reader;
             _rowId = handle.RowId;
index f738b0e..bc3637d 100644 (file)
@@ -2661,6 +2661,21 @@ namespace System.Reflection.Metadata.Tests
         }
 
         [Fact]
+        public void GetMethodDebugInformation_InvalidHandle()
+        {
+            using (var provider = MetadataReaderProvider.FromPortablePdbStream(new MemoryStream(PortablePdbs.DocumentsPdb)))
+            {
+                var reader = provider.GetMetadataReader();
+                var mdi = reader.GetMethodDebugInformation(default(MethodDebugInformationHandle));
+
+                Assert.Throws<BadImageFormatException>(() => mdi.SequencePointsBlob);
+                Assert.Throws<BadImageFormatException>(() => mdi.Document);
+                Assert.Throws<BadImageFormatException>(() => mdi.LocalSignature);
+                Assert.Throws<BadImageFormatException>(() => mdi.GetSequencePoints());
+            }
+        }
+
+        [Fact]
         public void GetCustomDebugInformation()
         {
             using (var provider = MetadataReaderProvider.FromPortablePdbStream(new MemoryStream(PortablePdbs.DocumentsPdb)))