mercredi 24 juin 2015

Debug a dynamically loaded DLL

I have a web app solution (let's say in C:\WebApp). At some point, I need to inject an external DLL from another solution (C:\Custom) and invoke a method in it.

I'm using this code:

public ActionResult ExecuteCustomAction()
{
    Assembly assembly = Assembly.LoadFile(@"C:\Custom\Custom\bin\Debug\Custom.dll");
    Object o = assembly.CreateInstance("Custom.Custom");
    if (o != null)
    {
        MethodInfo method = o.GetType().GetMethod("Execute");
        Object[] ob = // some params
        if (method != null)
        {
            Object returnValue = method.Invoke(o, ob).ToString();
            return new HttpStatusCodeResult(HttpStatusCode.OK);
        }
    }
    return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
}

No problem until now.

I would like to be able to debug the invoked method (the Custom solution is open in another VS instance), but didn't succeed.

I disabled the "Just my code" option, the Debug/Windows/Modules shows that the symbols for Custom.dll are loaded correctly, I can attach both VS instances (WebApp VS and Custom VS) to the w3wp process, but the execution never stops on the breakpoint I put inside the Execute method.

I'm not familiar with this, am I missing something obvious ?





Aucun commentaire:

Enregistrer un commentaire