Visual Studio Just-in-Time Debugger quits immediately - c#

I have a WinForms managed application which calls into a native C++ dll. I have enabled mixed managed and unmanaged debugging for the project and I'm able to step into the unmanaged code when debugging the project.
I'm interested in JIT debugging because it's much faster to run the debug build outside the debugger and start debugging only after some assertion is violated. JIT Debugger works fine, when the exception is raised in the managed code. It also work when I JIT debug a standalone C++ application. But whenever an exception is raised inside the unmanaged code which is invoked from the WinForms application, the JIT debugger quits immediately after I initiate the debugging session. I have enabled all the JIT debuggers in Options/Debugging/Just-In-Time list. Is this scenario supported at all?
UPDATE
I've run some more tests, and I can see that
This problem is not specific to WinForms applications. JIT Debug also fails when a managed console application calls into a native dll, which raises an assertion exception.
The problem does not seem to depend on framework version. I tried versions 3.5, 4, 4.5, 4.6.
The debugger also fails to break on an assertion exception in the unmanaged code, when I attach the debugger to its managed host application.

I have gone through this situation before. I think the problem is that the exception is uncatched by debugger.
I did the following and maybe this would be helpful.
Click Debug->Windows->Exception Settings.
Or you just search "exception" at quick Launch.
You may find a lot of exception is not catched by default setting.

I feel stupid. The solution was right in front of me.
There's an option in Visual Studio Just-In-Time Debugger dialog. It's called "Manually choose the debugging engines". Both Managed and Native engines have to be selected.

Related

Visual Studio debugger wait for managed code

I am writing C# plugin (DLL library) for a native\unmanaged application. The problem is that when I start debugger, the application runs and almost immediately exits (probably because my DLL is not loaded on application startup, but later). Checking "Enable native code debugging" helps, but significantly slows down application performance which is undesirable, because I only want to debug my C# code. Is there any way to debug DLL without enabling that option? I'm using Visual Studio 2015 Community.
I've figured it out. :)
Enable "Use managed compatibility mode" in Options->Debugging->General.

Breakpoint not getting hit in managed code

I am using Visual Studio 2010 & .NET Framework 3.5.
In my solution, I have a C++ project and a C# project. The C++ code in the former project invokes the managed code in the latter via (reverse) COM Interop. Both the dlls would get loaded into an external application. Both the projects are configured to start the same application when debugging is started.
Problem:
While debugging native code, the breakpoints are hit; however, while i want to debug the managed code, the breakpoints never get hit. This is the behavior regardless of the whether i start the application from native project or managed project.
Options Tried:
Setting the Debugger Type option in Native project properties to Mixed / Managed Only. Either case doesn't help.
Enabling / Disabling 'Enable Unmanaged code debugging' in Managed project properties also does not help.

Debugging A VC++ 6 DLL Called From C#

I have an old DLL written in Visual Studio 6 which I am calling from C# written in Visual Studio 2010. The DLL is not working properly and I want to debug into it. How can I do this? I have the source code project but cannot see how I can step into it.
Note: When I say "doesn't work", the call to the DLL succeeds and it gets a little way through the code in the DLL before failing, but I want to track down exactly where.
The technique of debugging a DLL is described here on MSDN. You'll need to do this from Visual Studio 6 (i.e. the tool that developed the DLL) and so the terminology will have changed. But the principles remain the same.
Attaching VS6 debugger on the .NET process shall work, as long you have the PDB file with the corresponding binary and the sources. You can break only on DLL code, however.
Attaching another VS+ shall work if the flag "Allow unmanaged debugging" is checked, but there is a possibility that symbols are not loaded by the debugger. A recompilation of the DLL shall solve the last problem.
Open Visual C++ Dll project, set breakpoint where you need. In the Project properties, Debug, Executable for debug session, type .NET executable file which uses this Dll. Start debugging (Go). When VC++ function is called, debugger breaks. Using this way, you can debug only unmanaged VC++ code.
Another way is to start debugging from .NET client in mixed debugging mode. Add VC++ project to the solution and rebuild it to debug both managed and unmanaged code.

Mixed mode debugging with Resharper on x64?

I have an .NET 4.0 application thats mostly in C#. It's got a managed C++ DLL that makes use of an unmanaged library. I'd like to debug the library from within ReSharper, but I'm on x64. If I use nunit and attach the debugger to the running nunit process everything works fine
is there any way to do what I need?
Actually there IS an issue with resharper here. We can debug in nunit, mstest and if we spin up out application and attach with a debugger. But basically no matter what you do you will NEVER get a breakpoint to hit in Resharper. And there is no error it just bypasses everything in the unmanaged code. There is at this point in time no solution that I can find that allows mixed mode debugging with resharper. Our organization struggled with this for several weeks. We eventually abandoned resharper for debugging in favor of plain mstest.
see the following:
http://devnet.jetbrains.net/thread/290349

Debugging 64-bit C++ from 64-bit .NET Code - how?

Visual studio tells me that 64-bit managed+unmanaged code debugging is not supported. Has anyone managed to resolve this problem?
I've seen this problem too with the 64-bit debugger. Do you definitely need to debug both at the same time?
If not, when you need to debug native code you could run the managed application and the attach the debugger manually selecting "Native Code" as the debug type (as opposed to Automatic which might select both Managed and Native).
Ctrl+F5, once running,
Debug->Attach to Process.
In the attach to: box select "Native code".
Make sure in the processes box your vshost app is highlighted.
Press "attach".
Now your break-points in your native cpp code should trigger and the debugger will kick in.

Categories