4

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 ?

EDIT: The sources are built locally, I also tried copying them in the app bin folder, referencing this path instead of the original one.

Razvan Dumitru
  • 11,815
  • 5
  • 34
  • 54
xlecoustillier
  • 16,183
  • 14
  • 60
  • 85

1 Answers1

-1

You should not use a DLL while debugging your code. A DLL is always considered a complete solution that is ready to be used in other program components.

Visual Studio doesn't allow you debugging a DLL that is imported from another project for that purpose.

Your solution is simple; debug your code (by including it in your app), make sure it is working fine, then move it to a separate DLL that is ready for any external usage.