From 0395f1be03bc76da77c902e89315dd66443483d3 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 16 Jan 2025 19:45:56 +0100 Subject: [PATCH 1/3] Ignore internal .NET Framework assemblies in AssemblySymbolLoader Resolves the false positive warnings in https://github.com/dotnet/aspnetcore/pull/59853 --- .../AssemblySymbolLoader.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs index 1d6921dd1f92..f9c3502c9bb1 100644 --- a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs +++ b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs @@ -16,6 +16,22 @@ namespace Microsoft.DotNet.ApiSymbolExtensions /// public class AssemblySymbolLoader : IAssemblySymbolLoader { + // This is a list of dangling .NET Framework internal assemblies that should never get loaded. + private static readonly HashSet s_assembliesToIgnore = [ +"System.ServiceModel.Internals.dll", +"Microsoft.Internal.Tasks.Dataflow.dll", +"MSDATASRC.dll", +"ADODB.dll", +"Microsoft.StdFormat.dll", +"stdole.dll", +"PresentationUI.dll", +"Microsoft.VisualBasic.Activities.Compiler.dll", +"SMDiagnostics.dll", +"System.Xaml.Hosting.dll", +"Microsoft.Transactions.Bridge.dll", +"Microsoft.Workflow.Compiler.dll" +]; + private readonly ILog _log; // Dictionary that holds the paths to help loading dependencies. Keys will be assembly name and // value are the containing folder. @@ -341,11 +357,14 @@ private void ResolveReferences(PEReader peReader, ImmutableHashSet? refe AssemblyReference reference = reader.GetAssemblyReference(handle); string name = $"{reader.GetString(reference.Name)}.dll"; + // Skip assemblies that should never get loaded because they are purely internal + if (s_assembliesToIgnore.Contains(name)) + continue; + // Skip reference assemblies that are loaded later. if (referenceAssemblyNamesToIgnore != null && referenceAssemblyNamesToIgnore.Contains(name)) continue; - // If the assembly reference is already loaded, don't do anything. if (_loadedAssemblies.ContainsKey(name)) continue; From 4b1103695ed246b78db47d29c24d2746dc2b770c Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 16 Jan 2025 19:58:59 +0100 Subject: [PATCH 2/3] Update src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs Co-authored-by: Eric StJohn --- .../AssemblySymbolLoader.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs index f9c3502c9bb1..38ea9a723045 100644 --- a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs +++ b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs @@ -18,19 +18,19 @@ public class AssemblySymbolLoader : IAssemblySymbolLoader { // This is a list of dangling .NET Framework internal assemblies that should never get loaded. private static readonly HashSet s_assembliesToIgnore = [ -"System.ServiceModel.Internals.dll", -"Microsoft.Internal.Tasks.Dataflow.dll", -"MSDATASRC.dll", -"ADODB.dll", -"Microsoft.StdFormat.dll", -"stdole.dll", -"PresentationUI.dll", -"Microsoft.VisualBasic.Activities.Compiler.dll", -"SMDiagnostics.dll", -"System.Xaml.Hosting.dll", -"Microsoft.Transactions.Bridge.dll", -"Microsoft.Workflow.Compiler.dll" -]; + "System.ServiceModel.Internals.dll", + "Microsoft.Internal.Tasks.Dataflow.dll", + "MSDATASRC.dll", + "ADODB.dll", + "Microsoft.StdFormat.dll", + "stdole.dll", + "PresentationUI.dll", + "Microsoft.VisualBasic.Activities.Compiler.dll", + "SMDiagnostics.dll", + "System.Xaml.Hosting.dll", + "Microsoft.Transactions.Bridge.dll", + "Microsoft.Workflow.Compiler.dll" + ]; private readonly ILog _log; // Dictionary that holds the paths to help loading dependencies. Keys will be assembly name and From 6f9ab84337c3dcda3409da02acc2122728d777ac Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 16 Jan 2025 20:02:10 +0100 Subject: [PATCH 3/3] Feedback --- .../AssemblySymbolLoader.cs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs index 38ea9a723045..f90efb19f4ad 100644 --- a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs +++ b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs @@ -18,18 +18,18 @@ public class AssemblySymbolLoader : IAssemblySymbolLoader { // This is a list of dangling .NET Framework internal assemblies that should never get loaded. private static readonly HashSet s_assembliesToIgnore = [ - "System.ServiceModel.Internals.dll", - "Microsoft.Internal.Tasks.Dataflow.dll", - "MSDATASRC.dll", - "ADODB.dll", - "Microsoft.StdFormat.dll", - "stdole.dll", - "PresentationUI.dll", - "Microsoft.VisualBasic.Activities.Compiler.dll", - "SMDiagnostics.dll", - "System.Xaml.Hosting.dll", - "Microsoft.Transactions.Bridge.dll", - "Microsoft.Workflow.Compiler.dll" + "System.ServiceModel.Internals", + "Microsoft.Internal.Tasks.Dataflow", + "MSDATASRC", + "ADODB", + "Microsoft.StdFormat", + "stdole", + "PresentationUI", + "Microsoft.VisualBasic.Activities.Compiler", + "SMDiagnostics", + "System.Xaml.Hosting", + "Microsoft.Transactions.Bridge", + "Microsoft.Workflow.Compiler" ]; private readonly ILog _log; @@ -355,12 +355,14 @@ private void ResolveReferences(PEReader peReader, ImmutableHashSet? refe foreach (AssemblyReferenceHandle handle in reader.AssemblyReferences) { AssemblyReference reference = reader.GetAssemblyReference(handle); - string name = $"{reader.GetString(reference.Name)}.dll"; + string nameWithoutExtension = reader.GetString(reference.Name); // Skip assemblies that should never get loaded because they are purely internal - if (s_assembliesToIgnore.Contains(name)) + if (s_assembliesToIgnore.Contains(nameWithoutExtension)) continue; + string name = nameWithoutExtension + ".dll"; + // Skip reference assemblies that are loaded later. if (referenceAssemblyNamesToIgnore != null && referenceAssemblyNamesToIgnore.Contains(name)) continue;