Repository: dotnet/runtime
File: src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderTests.cs (C#)

Code before:
                var importScope = reader.GetImportScope(default(ImportScopeHandle));

                Assert.Throws<BadImageFormatException>(() => importScope.Parent);
                Assert.Throws<BadImageFormatException>(() => importScope.ImportsBlob);
            }
        }

        [Fact]
        public void GetAssemblyFile_InvalidHandle()
        {
            var reader = GetMetadataReader(Misc.Members);
            var entity = reader.GetAssemblyFile(default(AssemblyFileHandle));

            Assert.Throws<BadImageFormatException>(() => entity.ContainsMetadata);
            Assert.Throws<BadImageFormatException>(() => entity.Name);
            Assert.Throws<BadImageFormatException>(() => entity.HashValue);
        }

        [Fact]
        public void GetAssemblyReference_InvalidHandle()
        {
            var reader = GetMetadataReader(Misc.Members);
            var entity = reader.GetAssemblyReference(default(AssemblyReferenceHandle));

            // Note: Version has special handling - when RowId == WinMDMscorlibRef (both 0 for regular assemblies),
            // it returns a static version without accessing the table. So we only test properties that do throw.
            Assert.Throws<BadImageFormatException>(() => entity.Flags);
            Assert.Throws<BadImageFormatException>(() => entity.Name);
            Assert.Throws<BadImageFormatException>(() => entity.Culture);
            Assert.Throws<BadImageFormatException>(() => entity.PublicKeyOrToken);
            Assert.Throws<BadImageFormatException>(() => entity.HashValue);
        }

        [Fact]
        public void GetConstant_InvalidHandle()
        {
            var reader = GetMetadataReader(Misc.Members);
            var entity = reader.GetConstant(default(ConstantHandle));

            Assert.Throws<BadImageFormatException>(() => entity.TypeCode);
            Assert.Throws<BadImageFormatException>(() => entity.Value);
            Assert.Throws<BadImageFormatException>(() => entity.Parent);
        }

        [Fact]
        public void GetCustomAttribute_InvalidHandle()
        {
            var reader = GetMetadataReader(Misc.Members);
            var entity = reader.GetCustomAttribute(default(CustomAttributeHandle));

            Assert.Throws<BadImageFormatException>(() => entity.Constructor);

Review comment (suggestion):
```suggestion
            // it returns a static version without accessing the table.
```
@copilot Delete this part of the comment and add a test for the Version special handling instead

Code after:
                var importScope = reader.GetImportScope(default(ImportScopeHandle));

                Assert.Throws<BadImageFormatException>(() => importScope.Parent);
                Assert.Throws<BadImageFormatException>(() => importScope.ImportsBlob);
            }
        }

        [Fact]
        public void GetAssemblyFile_InvalidHandle()
        {
            var reader = GetMetadataReader(Misc.Members);
            var entity = reader.GetAssemblyFile(default(AssemblyFileHandle));

            Assert.Throws<BadImageFormatException>(() => entity.ContainsMetadata);
            Assert.Throws<BadImageFormatException>(() => entity.Name);
            Assert.Throws<BadImageFormatException>(() => entity.HashValue);
        }

        [Fact]
        public void GetAssemblyReference_InvalidHandle()
        {
            var reader = GetMetadataReader(Misc.Members);
            var entity = reader.GetAssemblyReference(default(AssemblyReferenceHandle));

            // Version has special handling - when RowId == WinMDMscorlibRef (both 0 for regular assemblies),
            // it returns a static version without accessing the table.
            Assert.Equal(new Version(4, 0, 0, 0), entity.Version);

            Assert.Throws<BadImageFormatException>(() => entity.Flags);
            Assert.Throws<BadImageFormatException>(() => entity.Name);
            Assert.Throws<BadImageFormatException>(() => entity.Culture);
            Assert.Throws<BadImageFormatException>(() => entity.PublicKeyOrToken);
            Assert.Throws<BadImageFormatException>(() => entity.HashValue);
        }

        [Fact]
        public void GetConstant_InvalidHandle()
        {
            var reader = GetMetadataReader(Misc.Members);
            var entity = reader.GetConstant(default(ConstantHandle));

            Assert.Throws<BadImageFormatException>(() => entity.TypeCode);
            Assert.Throws<BadImageFormatException>(() => entity.Value);
            Assert.Throws<BadImageFormatException>(() => entity.Parent);
        }

        [Fact]
        public void GetCustomAttribute_InvalidHandle()
        {
            var reader = GetMetadataReader(Misc.Members);
            var entity = reader.GetCustomAttribute(default(CustomAttributeHandle));