简体   繁体   English

通过COM从C ++解决方案调试C#dll

[英]Debug C# dll from C++ solution via COM

I have a C++ solution. 我有一个C ++解决方案。 The startup project is an exe. 启动项目是一个exe。 In the solution there are a number C# dlls (targeting .NET Framework 2.0) that are registered for COM interop. 在解决方案中,有一些C#dll(针对.NET Framework 2.0)已注册COM interop。 When I put a breakpoint in the C# code I get the hollow red breakpoint with "No native symbols in symbol file" 当我在C#代码中放置一个断点时,我得到了空心的红色断点, "No native symbols in symbol file"

I have tried setting Project Property Pages -> Debugging -> Debugger Type to Mixed on the start-up project that calls the COM methods. 我已经尝试在调用COM方法的启动项目中将Project Property Pages -> Debugging -> Debugger Type为Mixed。

I have checked Debug -> Windows -> Modules . 我检查了Debug -> Windows -> Modules It has loaded my dlls, and the symbol status is "No native symbols in symbol file" . 它已加载我的dll,符号状态为"No native symbols in symbol file"

This is not the end of the world because if I do Debug -> Start Without Debugging and then Debug -> Attach to Process , changing the Attach To: to Managed (v2.0, v1.1, v1.0) code, Native code . 这不是世界末日,因为如果我执行Debug -> Start Without Debugging然后Debug -> Attach to Process ,将Attach To:更改为Managed (v2.0, v1.1, v1.0) code, Native code Then I hit breakpoints in both the C++ code and C# code. 然后我在C ++代码和C#代码中都遇到了断点。

So I have my workaround but I reckon if I can do it by attaching to process - I should be able to do it by just debugging. 所以我有我的解决方法,但我认为如果我可以通过附加到进程来做到 - 我应该能够通过调试来做到这一点。

How can I hit my C# breakpoints by just doing Debug -> Start Debugging ? 如何通过Debug -> Start Debugging来点击我的C#断点?

I was able to debug my C# dll from a C++ project in VS2008 by doing the following: 我可以通过执行以下操作从VS2008中的C ++项目调试我的C#dll:

In the C++ project's properties, goto Configuration Properties -> Debugging. 在C ++项目的属性中,转到配置属性 - >调试。 Set "Debugger Type" to Mixed. 将“调试器类型”设置为“混合”。 "Attach" should be set to No. “附加”应设置为“否”。

In your C# project properties, in the Debug tab, set the "Start External Program" to your C++ project's executable. 在C#项目属性中的Debug选项卡中,将“Start External Program”设置为C ++项目的可执行文件。

I know it's a little bit old but I found a practical solution for the problem. 我知道它有点旧,但我找到了解决问题的实用方法。

I had the same problem while using a C++ application which uses a C# COM-Object. 在使用使用C#COM-Object的C ++应用程序时遇到了同样的问题。 I tried several settings within Visual Studio on the C++ and C# side. 我在C ++和C#端的Visual Studio中尝试了几个设置。 Nothing helps until I tried manually launching the Debugger. 在我尝试手动启动调试器之前没有任何帮助。

You can use 您可以使用

Debugger.Launch();

to manually start the Debugger on your C# DLL. 手动启动C#DLL上的调试器。 I know this is not the best but a practical way. 我知道这不是最好的,而是一种实用的方法。 In later productive environments you have to remove the Debugger launch function :). 在以后的生产环境中,您必须删除调试器启动功能:)。

Regards 问候

I am unsure if this will help but we work a lot with C# and C++. 我不确定这是否有帮助,但我们使用C#和C ++工作很多。 I found this to be possible by placing the C++ project and the C# project in the same solution and enabling "native debugging" in the C# project. 我发现这可以通过将C ++项目和C#项目放在同一个解决方案中并在C#项目中启用“本机调试”来实现。 Then I was able to jump back and forth between them while debugging. 然后我可以在调试时在它们之间来回跳转。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM