From 957427c3f89cfbebd81cadd1d15b9890e5075f83 Mon Sep 17 00:00:00 2001 From: Tim Jones Date: Fri, 22 Nov 2024 23:47:33 +0000 Subject: [PATCH] Fix document checksums in emitted pdbs --- .../src/System/Reflection/Emit/ModuleBuilderImpl.cs | 2 +- .../tests/PortablePdb/PortablePdbStandalonePdbTest.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs index 5d242a710ae2b..bbd52a5b7a0df 100644 --- a/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs +++ b/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs @@ -603,7 +603,7 @@ private DocumentHandle AddDocument(string url, Guid language, Guid hashAlgorithm _pdbBuilder.AddDocument( name: _pdbBuilder.GetOrAddDocumentName(url), hashAlgorithm: hashAlgorithm == default ? default : _pdbBuilder.GetOrAddGuid(hashAlgorithm), - hash: hash == null ? default : _metadataBuilder.GetOrAddBlob(hash), + hash: hash == null ? default : _pdbBuilder.GetOrAddBlob(hash), language: language == default ? default : _pdbBuilder.GetOrAddGuid(language)); private void FillMemberReferences(ILGeneratorImpl il) diff --git a/src/libraries/System.Reflection.Emit/tests/PortablePdb/PortablePdbStandalonePdbTest.cs b/src/libraries/System.Reflection.Emit/tests/PortablePdb/PortablePdbStandalonePdbTest.cs index e1ce56f151d81..7315afe2ded47 100644 --- a/src/libraries/System.Reflection.Emit/tests/PortablePdb/PortablePdbStandalonePdbTest.cs +++ b/src/libraries/System.Reflection.Emit/tests/PortablePdb/PortablePdbStandalonePdbTest.cs @@ -61,7 +61,8 @@ private static void ValidatePDB(MethodBuilder method, MethodBuilder entryPoint, Document doc = reader.GetDocument(docEnumerator.Current); Assert.Equal("MySourceFile.cs", reader.GetString(doc.Name)); Assert.Equal(SymLanguageType.CSharp, reader.GetGuid(doc.Language)); - Assert.Equal(default, reader.GetGuid(doc.HashAlgorithm)); + Assert.Equal(new Guid("8829d00f-11b8-4213-878b-770e8597ac16"), reader.GetGuid(doc.HashAlgorithm)); + Assert.Equal("06CBAB3A501306FDD9176A00A83E5BB92EA4D7863CFD666355743527CF99EDC6", Convert.ToHexString(reader.GetBlobBytes(doc.Hash))); Assert.False(docEnumerator.MoveNext()); MethodDebugInformation mdi1 = reader.GetMethodDebugInformation(MetadataTokens.MethodDebugInformationHandle(method.MetadataToken)); @@ -147,6 +148,7 @@ private static MetadataBuilder GenerateAssemblyAndMetadata(out MethodBuilder met ModuleBuilder mb = ab.DefineDynamicModule("MyModule2"); TypeBuilder tb = mb.DefineType("MyType", TypeAttributes.Public | TypeAttributes.Class); ISymbolDocumentWriter srcdoc = mb.DefineDocument("MySourceFile.cs", SymLanguageType.CSharp); + srcdoc.SetCheckSum(new Guid("8829d00f-11b8-4213-878b-770e8597ac16"), Convert.FromHexString("06CBAB3A501306FDD9176A00A83E5BB92EA4D7863CFD666355743527CF99EDC6")); method = tb.DefineMethod("SumMethod", MethodAttributes.Public | MethodAttributes.Static, typeof(int), [typeof(int), typeof(int)]); ILGenerator il1 = method.GetILGenerator(); LocalBuilder local = il1.DeclareLocal(typeof(int));