From 7cc893279931276cbbb5d6797643549e0858965c Mon Sep 17 00:00:00 2001 From: Mike Barnett Date: Thu, 9 Jul 2020 09:41:39 -0700 Subject: [PATCH] Gracefully decline to use portable PDB files: issue a message in the log and skip reading them in when reading in the assembly they belong to. --- ILMerge/ILMerge.cs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/ILMerge/ILMerge.cs b/ILMerge/ILMerge.cs index daea984..190532b 100644 --- a/ILMerge/ILMerge.cs +++ b/ILMerge/ILMerge.cs @@ -789,16 +789,27 @@ private bool AttributeExistsInTarget(AttributeNode possiblyDuplicateAttr, Attrib return addAttribute; } - + private static bool IsPortablePdb(string pdb) { + using (var stream = File.OpenRead(pdb)) { + const uint ppdb_signature = 0x424a5342; + var position = stream.Position; + try { + var reader = new BinaryReader(stream); + return reader.ReadUInt32() == ppdb_signature; + } finally { + stream.Position = position; + } + } + } #endregion #region Protected Methods - /// - /// Provides a way for subtypes to create their own Duplicator to use for - /// the merging. When not overridden, the duplicator is the standard one. - /// - /// Top level module for this duplicator to copy types into. - /// The duplicator to use for visiting the source modules. - protected virtual Duplicator CreateDuplicator(Module module) { + /// + /// Provides a way for subtypes to create their own Duplicator to use for + /// the merging. When not overridden, the duplicator is the standard one. + /// + /// Top level module for this duplicator to copy types into. + /// The duplicator to use for visiting the source modules. + protected virtual Duplicator CreateDuplicator(Module module) { return new Duplicator(module, null); } /// @@ -1880,6 +1891,13 @@ public void Merge() { WriteToLog("Can not find PDB file. Debug info will not be available for assembly '{0}'.", (string)assemblyNames[i]); tempDebugInfo = false; + } else + { + if (IsPortablePdb(pdbFullName)) + { + WriteToLog("Can not use portable PDB file. Debug info will not be available for assembly '{0}'.", (string)assemblyNames[i]); + tempDebugInfo = false; + } } } AssemblyNode a;