Skip to content

Instantly share code, notes, and snippets.

@chamons

chamons/foo.diff Secret

Created Nov 14, 2017
Embed
What would you like to do?
diff --git a/Mono.Cecil.Cil/Symbols.cs b/Mono.Cecil.Cil/Symbols.cs
index 6ef5ad2..0e0d5aa 100644
--- a/Mono.Cecil.Cil/Symbols.cs
+++ b/Mono.Cecil.Cil/Symbols.cs
@@ -751,15 +751,17 @@ namespace Mono.Cecil.Cil {
public class DefaultSymbolReaderProvider : ISymbolReaderProvider {
readonly bool throw_if_no_symbol;
+ readonly bool throw_if_mismatch;
public DefaultSymbolReaderProvider ()
: this (throwIfNoSymbol: true)
{
}
- public DefaultSymbolReaderProvider (bool throwIfNoSymbol)
+ public DefaultSymbolReaderProvider (bool throwIfNoSymbol, bool throwIfMismatch = true)
{
throw_if_no_symbol = throwIfNoSymbol;
+ throw_if_mismatch = throwIfMismatch;
}
public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName)
@@ -784,7 +786,11 @@ namespace Mono.Cecil.Cil {
return SymbolProvider.GetReaderProvider (SymbolKind.NativePdb).GetSymbolReader (module, fileName);
} catch (TypeLoadException) {
// We might not include support for native pdbs.
+ } catch (Exception e) {
+ if (throw_if_mismatch || e.GetType ().FullName != "Mono.CompilerServices.SymbolWriter.MonoSymbolFileException")
+ throw;
}
+
}
var mdb_file_name = Mixin.GetMdbFileName (fileName);
@@ -793,6 +799,9 @@ namespace Mono.Cecil.Cil {
return SymbolProvider.GetReaderProvider (SymbolKind.Mdb).GetSymbolReader (module, fileName);
} catch (TypeLoadException) {
// We might not include support for mdbs.
+ } catch (Exception e) {
+ if (throw_if_mismatch || e.GetType ().FullName != "Mono.CompilerServices.SymbolWriter.MonoSymbolFileException")
+ throw;
}
}
diff --git a/Test/Mono.Cecil.Tests/AssemblyTests.cs b/Test/Mono.Cecil.Tests/AssemblyTests.cs
index 0d484de..5e234a1 100644
--- a/Test/Mono.Cecil.Tests/AssemblyTests.cs
+++ b/Test/Mono.Cecil.Tests/AssemblyTests.cs
@@ -83,5 +83,24 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (module.AssemblyReferences [0], module.TypeSystem.CoreLibrary);
}, verify: !Platform.OnMono);
}
+
+ [Test]
+ public void MismatchedLibraryAndSymbols_DoNotThrow ()
+ {
+ // SQLite-net.dll (from nuget) shiped with mismatched symbol files, but throwIfNoSymbol did not prevent it from throwing
+ string assemblyPath = BaseTestFixture.GetAssemblyResourcePath ("SQLite-net.dll", typeof (AssemblyTests).Assembly ());
+
+ Assert.Throws <CompilerServices.SymbolWriter.MonoSymbolFileException> (() =>
+ AssemblyDefinition.ReadAssembly (assemblyPath, new ReaderParameters {
+ ReadSymbols = true,
+ SymbolReaderProvider = new Cil.DefaultSymbolReaderProvider (throwIfNoSymbol: false)
+ })
+ );
+
+ AssemblyDefinition.ReadAssembly (assemblyPath, new ReaderParameters {
+ ReadSymbols = true,
+ SymbolReaderProvider = new Cil.DefaultSymbolReaderProvider (throwIfNoSymbol: false, throwIfMismatch: false)
+ });
+ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment