Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you debug an assembly loaded through Assembly.Load(byte[])?

I am creating a plugin for a product that loads plugin DLLs using Assembly.Load(byte[]). This is all very well and good, but it means that I have no conventional means of loading the debugging symbols to step through my code.

The crazy thing is, several months ago I was having the exact same issue and solved it - and boy was I proud of myself! So I know it can be done, I've just forgotten how!

I have a few vague memories of things I might have tried, but I can't tease the details out of my head:

  • .NET Reflector
    • Probably wrong though because I distinctly remember stepping through the original .cs file
  • Using IIS Express rather than Cassini
    • But this strikes me as a weird solution - the assembly is loaded from a byte-array, so the framework knows nothing about where the DLL came from or what an appropriate PDB might look like if it saw one. This problem should exist in any environment.
  • Loading the symbols manually through the "Modules" window
    • Tried this; I get "The symbol file xxxxx.pdb does not match the module" - because, of course, we're loading from a byte-array, not the DLL itself.
like image 615
Iain Fraser Avatar asked Oct 22 '12 03:10

Iain Fraser


1 Answers

If your assembly is strongly named, you can put the assembly in the GAC. Strongly named assemblies are always loaded from the GAC, even if it is loaded via Assembly.Load(byte[]). Then just put your in symbols in C:\Windows\symbols\dll or where ever is convenient. I do this all the time to debug our own product's plugin DLLs which are loaded by another application in a similar manner.

You can use gacutil to install it in the GAC. Remember to remove it when you're done debugging or you might end up running tests against an old version you GAC'd and forgot about.

like image 62
Mike Zboray Avatar answered Oct 15 '22 15:10

Mike Zboray