From 553ea3f6988e5869c5196132b1c74987b42ca8db Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 6 May 2011 14:27:00 +0200 Subject: [PATCH] Ignore exceptions while reading debug symbols. Closes #169. --- ILSpy/LoadedAssembly.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 29cc0c59e..8285be9ae 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -88,24 +88,28 @@ namespace ICSharpCode.ILSpy // runs on background thread ReaderParameters p = new ReaderParameters(); p.AssemblyResolver = new MyAssemblyResolver(this); - try { - if (DecompilerSettingsPanel.CurrentDecompilerSettings.UseDebugSymbols) { - SetSymbolSettings(p); + AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, p); + if (DecompilerSettingsPanel.CurrentDecompilerSettings.UseDebugSymbols) { + try { + LoadSymbols(asm.MainModule); + } catch (IOException) { + } catch (UnauthorizedAccessException) { + } catch (InvalidOperationException) { + // ignore any errors during symbol loading } - return AssemblyDefinition.ReadAssembly(fileName, p); - } finally { - if (p.SymbolStream != null) - p.SymbolStream.Dispose(); } + return asm; } - private void SetSymbolSettings(ReaderParameters p) + private void LoadSymbols(ModuleDefinition module) { // search for pdb in same directory as dll string pdbName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".pdb"); if (File.Exists(pdbName)) { - p.ReadSymbols = true; - p.SymbolStream = File.OpenRead(pdbName); + using (Stream s = File.OpenRead(pdbName)) { + module.ReadSymbols(new Mono.Cecil.Pdb.PdbReaderProvider().GetSymbolReader(module, s)); + } + return; } // TODO: use symbol cache, get symbols from microsoft