views:

36

answers:

1

I have some code that references an outside DLL which in production will be loaded by a factory. The DLL shouldn't be referenced directly by my assembly, it will be loaded at runtime using Assembly.Load().

This all works just fine, but when it comes to debugging, I want to be able to step through the library as if I'd referenced it using something like new MyConcreteObject().

I know that I can use #if #endif to compile code differently in debug/release - but can I also have a reference that is only attached in debug/release?

If I can, and that is how I should do this, how do I go about it? If not, how should I be going about this?

Currently I have:

public class ObjectFactory
{
    public IObject CreateObject(string objectType)
    {
        /* Code to load and return the concrete object specified in the app.config */
    }
}

public class Program
{
    public void Main(string[] args)
    {
        IObject obj = ObjectFactory.CreateObject("MyObject, MyObjectLibrary");
        obj.DoYourStuff();
    }
}

So now I want to step through the code for the "DoYourStuff()" method and I don't want to have to comment out the line that loads my object and replace it with:

IObject obj = new MyObject();

Which then requires a project reference pointing to the MyObjectLibrary DLL that will require I remove the reference and uncomment out the CreateObject() call and instead comment out the line that new's up the concrete object.

Make sense?

+1  A: 

You don't need to have a reference in VS to debug anything. As long as you have the pdbs for the dynamically-loaded module available (either in the original build location or in the directory with the code you're debugging), it'll debug just fine. Just set the breakpoints normally in VS- if it's working, you should see the breakpoint turn solid in VS when the pdb for the module in question is loaded. Check the modules window if not.

nitzmahone
I can't believe I didn't know that... thanks
BenAlabaster