Finding the Source Code for an Assembly

Sometimes, especially when working on large projects (such as, I don't know, say ... the CLR), you find yourself debugging a problem where you don't know where a component is built from.  Depending on the problem, it might be useful to get to the sources of the assembly to help diagnose what the issue is (or to look up in the source control system who the owner of the code is so you can contact them).  I ran into this problem recently, and using the IronPython MDbg extension was able to whip up a quick method that will dump the path to the source files that make up an assembly that you have symbols for:

def ShowAssemblySources(assembly):
    for module in Shell.Debugger.Processes.Active.Modules:
        if module.CorModule.Assembly.Name.Contains(assembly):
            print module.CorModule.Name
            if module.SymReader != None:
                for document in module.SymReader.GetDocuments():
                    print "  %s" % document.URL
                print "  module does not have symbols, skipping"

Using this method is pretty straight forward:

[p#:0, t#:0] mdbg> ShowAssemblySources("caspol")

It's definately not an every-day debugging tool, which again makes it nice that IronPython makes extending the MDbg command set so easy since I wouldn't have wanted to spend more than a few minutes working this code out.

Comments (2)

  1. Reflector has had the search feature for ages. You should give it a shot.

  2. Reflector can tell you where the source files are? How do you access that feature in the Reflector UI?


Skip to main content