Visual Studio 2005:从另一个项目调试C#代码?

时间:2023-01-16 17:58:15

I have a desktop application I'm developing with Visual Studio where I need to update a small part of the app on a more frequent basis. To avoid the inconvenience of deploying a new installer every time, I split the more frequently updated support functions into a separate project and compiled it as a DLL. The desktop app now loads this DLL at runtime with reflection and then instantiates the object inside it based on a shared DLL with an interface definition, like this:

我有一个桌面应用程序,我正在使用Visual Studio进行开发,我需要更频繁地更新应用程序的一小部分。为了避免每次部署新安装程序带来的不便,我将更频繁更新的支持功能拆分为一个单独的项目,并将其编译为DLL。桌面应用程序现在在运行时使用反射加载此DLL,然后基于具有接口定义的共享DLL实例化其中的对象,如下所示:

Assembly a = Assembly.LoadFrom(supportDLLPath);
ISupportModuleInterface obj = (ISupportModuleInterface)a.CreateInstance("SupportCode.SupportObject");
if (obj != null)
{
    obj.OnTransferProgress += new FileTransferProgressHandler(obj_OnTransferProgress);
    obj.OnTransferComplete += new EventHandler(uploader_OnTransferComplete);
    obj.DoWork(packagePath)
}

It works fine most of the time, but I need to debug an issue with it and I can't reliably get the Visual Studio debugger to step into it. Sometimes when pressing F11 through the code, such as when stepping into DoWork, it will automatically locate the source code for the DLL on my system and display it. However, when an event is fired, Visual Studio just displays the [External Code] marker in the Call Stack and I can't navigate inside the code in the support project.

它在大多数情况下工作正常,但我需要调试它的问题,我无法可靠地让Visual Studio调试器进入它。有时当通过代码按F11时,例如当进入DoWork时,它会自动在我的系统上找到DLL的源代码并显示它。但是,当事件被触发时,Visual Studio只显示调用堆栈中的[外部代码]标记,我无法在支持项目中的代码内导航。

Does anyone have any ideas on how to fix this so I can properly debug the support project? Thank you!

有没有人对如何解决这个问题有任何想法,所以我可以正确调试支持项目?谢谢!

2 个解决方案

#1


Is the assembly listed in the "Modules" window (Debug -> Windows -> Modules, or press "Ctrl-D, M"), and is it listed as "Symbols Loaded.", with the symbols loaded from the location that you expect? (You can force it to load symbols by right clicking and selecting "Load symbols...". If it cant find a symbol file that matches it will prompt you with an "Open..." dialog).

是否在“模块”窗口中列出了程序集(调试 - > Windows - >模块,或按“Ctrl-D,M”),并将其列为“已加载符号”。从您所在的位置加载符号期望? (您可以通过右键单击并选择“加载符号...”来强制它加载符号。如果找不到与其匹配的符号文件,则会提示您“打开...”对话框)。

Also check in this window to make sure that the module isnt loaded twice, and that the version / timestamp / location of the assembly is what you would expect it to be.

同时检查此窗口以确保模块未加载两次,并且程序集的版本/时间戳/位置是您所期望的。

Finally check to see if "Just My Code" is chcked under "Tools -> Options -> Debugging", and see if unchecking it makes a difference.

最后检查“工具 - >选项 - >调试”下的“只是我的代码”是否被清除,看看取消选中是否有所不同。

#2


Can you step into disassembly? If so from what I remember, it will give you a path to where the source code was when pdb was created. I had to do this to debug NHibernate and had to place the source code on the exact path where it was when 'pdb' file was created. After that I could step into source code with no problems.

你能步入拆卸吗?如果是这样,我会记得,它将为您提供创建pdb时源代码所在位置的路径。我必须这样做来调试NHibernate,并且必须将源代码放在创建'pdb'文件时的确切路径上。之后我可以毫无问题地进入源代码。

#1


Is the assembly listed in the "Modules" window (Debug -> Windows -> Modules, or press "Ctrl-D, M"), and is it listed as "Symbols Loaded.", with the symbols loaded from the location that you expect? (You can force it to load symbols by right clicking and selecting "Load symbols...". If it cant find a symbol file that matches it will prompt you with an "Open..." dialog).

是否在“模块”窗口中列出了程序集(调试 - > Windows - >模块,或按“Ctrl-D,M”),并将其列为“已加载符号”。从您所在的位置加载符号期望? (您可以通过右键单击并选择“加载符号...”来强制它加载符号。如果找不到与其匹配的符号文件,则会提示您“打开...”对话框)。

Also check in this window to make sure that the module isnt loaded twice, and that the version / timestamp / location of the assembly is what you would expect it to be.

同时检查此窗口以确保模块未加载两次,并且程序集的版本/时间戳/位置是您所期望的。

Finally check to see if "Just My Code" is chcked under "Tools -> Options -> Debugging", and see if unchecking it makes a difference.

最后检查“工具 - >选项 - >调试”下的“只是我的代码”是否被清除,看看取消选中是否有所不同。

#2


Can you step into disassembly? If so from what I remember, it will give you a path to where the source code was when pdb was created. I had to do this to debug NHibernate and had to place the source code on the exact path where it was when 'pdb' file was created. After that I could step into source code with no problems.

你能步入拆卸吗?如果是这样,我会记得,它将为您提供创建pdb时源代码所在位置的路径。我必须这样做来调试NHibernate,并且必须将源代码放在创建'pdb'文件时的确切路径上。之后我可以毫无问题地进入源代码。