[英]Attach/Debug Plugin DLL That Has Been Dynamically Loaded By A Third Party Application?
[英]Debug a dynamically loaded DLL
我有一個Web應用程序解決方案(假設在C:\\WebApp
)。 在某些時候,我需要從另一個解決方案( C:\\Custom
)注入一個外部DLL並調用其中的方法。
我正在使用此代碼:
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);
}
直到現在都沒問題。
我希望能夠調試調用的方法(自定義解決方案在另一個VS實例中打開),但沒有成功。
我禁用了“只是我的代碼”選項,Debug / Windows / Modules顯示正確加載了Custom.dll的符號,我可以將兩個VS實例(WebApp VS和自定義VS)附加到w3wp
進程,但執行從不在我放入Execute
方法的斷點上停止。
我不熟悉這個,我錯過了一些明顯的東西嗎?
編輯:源是在本地構建的,我也嘗試在app bin文件夾中復制它們,引用此路徑而不是原始路徑。
調試代碼時不應使用DLL。 DLL始終被視為可以在其他程序組件中使用的完整解決方案。
Visual Studio不允許您調試從其他項目導入的DLL。
你的解決方案很簡單; 調試你的代碼(通過將其包含在你的應用程序中),確保它正常工作,然后將其移動到一個單獨的DLL,可以用於任何外部使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.