1

I tried to use a PDB file to map the Instructions to the Sequencepoints in Mono.Cecil and find out the line number of a method. But none of the answers in any forum seems to work, because no matter what I try the SymbolsNotMatchingException is thrown with the error message

Symbols were found but are not matching the assembly".

By the way, my target "application" is a Unity Game.

Here is some code I use (side note: ProjectPath is the path to my target *.dll):

var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory(GetDLLsFolderToResolve(ProjectPath));

using var assembly = AssemblyDefinition.ReadAssembly(ProjectPath,
                new ReaderParameters { ReadWrite = true, AssemblyResolver = resolver, 
                    SymbolReaderProvider = new PdbReaderProvider(), ReadSymbols = true });

I have already the Mono.Cecil.dll and Mono.Cecil.Pdb.dll in the same folder due to import Mono.Cecil via NuGet. Also, the target DLL and the PDB also are in the same folder.

Does anybody have a working example? Or any idea how this error could be solved? Would be happy for any help.

4
  • are you sure PDB actually matches the file?
    – Igor Skochinsky
    Jul 3, 2021 at 19:59
  • I don't know if they are matching each other, but the *.dll's and *.pdb's were created in the same folder after the build process. Maybe I choose the wrong settings for the Unity build process. I will have a look, thank you! :) Jul 3, 2021 at 21:30
  • Can't believe that this hint helped me to solve it. I have modified the *.dll with Mono.Cecil before and it doesn't match afterwards with the *.pdb file. Thank you so much! Jul 3, 2021 at 21:57
  • @programming_is_bae please write this up as an answer and accept it. It's perfectly fine to do that here and you may even get some upvotes for it. Most importantly it will help others who ran into the same issue.
    – 0xC0000022L
    Jul 5, 2021 at 6:54

1 Answer 1

3

So all the steps above are correct the way they were described. The only thing I have done wrong was, that my target DLL was modified by Mono.Cecil before (I already had read and wrote my target DLL and modified it by this way). So the DLL and the PDB was not the same anymore.

So if you want to run Mono.Cecil just once and you get the exception above do the following things:

  1. Build your target application again (which should have all the DLL's and the corresponding PDB's for each DLL)
  2. Add ReadSymbols = true to the ReadParameters (in my case I don't want to write, so I need only the ReadParameters)
  3. Run your Mono.Cecil application

Note: This is only a solution if you want to run Mono.Cecil once. If you want to run it again over your target DLL, you have to make all steps above again.

Hopefully this will help someone!

~Sulan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.