diff --git a/src/tasks/MonoTargetsTasks/MarshalingPInvokeScanner/MarshalingPInvokeScanner.cs b/src/tasks/MonoTargetsTasks/MarshalingPInvokeScanner/MarshalingPInvokeScanner.cs index 850d3c787b50d..5f7ec7fd590e3 100644 --- a/src/tasks/MonoTargetsTasks/MarshalingPInvokeScanner/MarshalingPInvokeScanner.cs +++ b/src/tasks/MonoTargetsTasks/MarshalingPInvokeScanner/MarshalingPInvokeScanner.cs @@ -74,14 +74,16 @@ private string[] ScanAssemblies(string[] assemblies) private void ResolveInconclusiveTypes(HashSet incompatible, string assyPath, MinimalMarshalingTypeCompatibilityProvider mmtcp) { - string assyName = MetadataReader.GetAssemblyName(assyPath).Name!; - HashSet inconclusiveTypes = mmtcp.GetInconclusiveTypesForAssembly(assyName); - if(inconclusiveTypes.Count == 0) - return; - using FileStream file = new FileStream(assyPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using PEReader peReader = new PEReader(file); + if (!peReader.HasMetadata) + return; // Just return. There are no metadata in the DLL to help us with remaining types. + MetadataReader mdtReader = peReader.GetMetadataReader(); + string assyName = mdtReader.GetString(mdtReader.GetAssemblyDefinition().Name); + HashSet inconclusiveTypes = mmtcp.GetInconclusiveTypesForAssembly(assyName); + if(inconclusiveTypes.Count == 0) + return; SignatureDecoder decoder = new(mmtcp, mdtReader, null!); @@ -107,9 +109,8 @@ private bool IsAssemblyIncompatible(string assyPath, MinimalMarshalingTypeCompat using FileStream file = new FileStream(assyPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using PEReader peReader = new PEReader(file); if (!peReader.HasMetadata) - { - return false; - } + return false; // No types in this DLL means no incompatible marshaling constructs. + MetadataReader mdtReader = peReader.GetMetadataReader(); foreach(CustomAttributeHandle attrHandle in mdtReader.CustomAttributes)