Cannot Debug in VS2017 with Windows 10 - c#

I have a solution with 4 projects, three of them are C++, and one is C#. I am trying to debug the C# one, but am unable to. Every single time I try, I get an error that says
Unable to start debugging. check your debugger settings by opening project properties and navigating to 'Configuration Properties -->Debugging'
Configuration is Debug, and the Platform is Any CPU. I am not debugging on a remote machine.
I have VS2017 installed on Windows 10.

Cannot Debug in VS2017 with Windows 10
According to the error message:
check your debugger settings by opening project properties and navigating to 'Configuration Properties -->Debugging'
This should be the debuger settings for C++ project rather than C# project:
C++:
C#:
So, first, you should make sure your StartUp Project is C# project. And for the C++ project, you can create a new blank C++ project, then compare the debugger settings of the problematic project with the settings of the new project.
Hope this helps.

Related

VC++ Interop DLL: Binary was not built with debug information

I have a VC++ (.exe) application built in Visual Studio 2019. In project properties I have set to generate debug information for it.
Configuration Properties --> C/C++ --> Debug information format --> Program Database for Edit and Continue (/ZI)
Configuration Properties --> Linker --> Debugging --> Generate Debug Info --> Generate Debug Information (/DEBUG) (Also I have tried here: Generate Debug Information optimized for sharing and publishing (/DEBUG:FULL)
In the output it generates three files:
myApp.exe
myApp.pdb
myApp.Interop.dll
Now from another C# app I launched this VC++ exe app by using Process.Start("myapp.exe") in order to communicate between them later.
Now I am trying to debug C# and VC++ apps so I open two instances of VS, one for each app.
From VS I start debugging the C# app and from the another VS I attach to the process VC++ app. In the VS where I have launched my C# app, in modules window I can see below message:
C:\Users\myUser\AppData\Local\assembly\dl3\C23J1LN6.XOZ\GJPNWB74.YC1\bdcce8ba\10fb0e7d_e918d801\myApp.Interop.dll --> Binary was not built with debug information
Why isn't it capable to find my myApp.pdb file that was generated? all myApp.* are in the same directory.
It looks like an issue with the debugger type that you are using in the solution with the C# project. Visual Studio will default to "Managed only" when debugging a C# project. However, you want to debug both the C# project and the associated C++ dll. When trying to load the symbols for a native application / shared library it will fail as if there were no valid symbols.
Depending on how you attach to the C# executable:
if you are starting the executable directly from Visual Studio, you need to check "Enable native code debugging" in the Debug tab of your project properties [1];
if you are starting the executable externally and only later attaching using Visual Studio, you need to select "Native" and "Managed" clicking on the Select button in the "Attach to" row.
References
[1] https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-debug-managed-and-native-code#configure-mixed-mode-debugging
[2] https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-debug-in-mixed-mode

A dependent dll was not found

My app does not run on "Release x86" when running the app it crashes immediately after the splash screen. Output shows the following exception:
The program '[8204] dfz.exe' has exited with code -1073741515 (0xc0000135) 'A dependent DLL was not found'.
It also tells me the module is build without symbols, however in build settings I have set debug info to Full.
The first time I build the app for the Windows Store it built correctly and I also published that version to the store. When I did a manual rebuild to check if ads where inserted correctly it would not run.
However, I can run the app on ARM and X64 with no problems on release. Only x86 with .Net native toolchain will throw the missing dependant DLL.
What I have tried so far:
Created a new project, Added all my files and Nuget packages, No dice
Removed and updated all my existing references.
Tried to debug the release version so i can find out what DLL is missing from the package. However it keeps telling me there are no symbol files.
I am looking for any suggestions I can try because I am really at a loss here of why it will not run on x86.
Edit:
A blank UWP project also returns the DLL error when i run it. It looks like i have a broken development environment.
Edit2:
Just did a remote debugging session to another laptop and the app worked with no problems. So the problem is an environment related issue.
Could one of the projects in your dependencies be configured specifically for x64?
Another thing to check is that one of your projects is not set to build for that configuration (I vaguely remember some problem I had years ago that sounds kind like your situation ... although not for windows store apps ... and it turned out one of my projects wasn't set to compile for the configuration I was selecting ).

How to debug the c++ dll from c# project?

I have created a visual c++ 6.0 dll project and using it from my c# code. Now i want to debug the dll but i am not able to do it.
I choose the following option to do it:
put the breaking point in my visual c++ project code.
build the dll and copy it into the directory of my c# project.
Now i build my c# project and dll works fine (method are calling perfectly).
Now i want to debug the dll.
I follow a blog and open the c++ project and choose the Attach to process from vc++.
but i am not able to find the running process of visual c# project, whereas it available at task manager process.
In my c# project solution i have two project i.e.
web service (i called the dll method at the time of accessing a url)
Another one is webform application which starts the web services.
Now please help me how should i debug my dll. I have followed so many blogs but all of them are focusing on Attaching process method which is not working in my condition. What should i do?
You'll need to enable unmanaged debugging, it is not turned on by default in either scenario because your main program is managed.
You do it in your C# project with Project > Properties > Debug tab > tick the "Enable unmanaged code debugging" checkbox.
You do it with Tools > Attach to Process by clicking the Select button. Choose the "Debug these code types" radio button and tick both Managed and Native. You may have to resort to only native if your process is 64-bit.
Set a breakpoint in the DLL's source code and be sure to write C# code that exercises the DLL function. If you still have trouble getting a breakpoint then use Debug > Windows > Modules and verify that you see the DLL in the module list. Get additional troubleshooting info by right-clicking it, select Symbol Load Information. Which shows a trace of where the debugger looked for the PDB file.
You can add C++ project to the your C# solution and add reference directly to the project (not dll), then you will not be needing to copy DLL. After that just start normal debugging (F5) of your C# project, and breakpoints will be working for C++ project too. This way will be very comfortable for debugging. I have tried such debugging and did not change any other settings.

Debug C# dll from C++ solution via COM

I have a C++ solution. The startup project is an exe. In the solution there are a number C# dlls (targeting .NET Framework 2.0) that are registered for COM interop. When I put a breakpoint in the C# code I get the hollow red breakpoint with "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.
I have checked Debug -> Windows -> Modules. It has loaded my dlls, and the symbol status is "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. Then I hit breakpoints in both the C++ code and C# code.
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?
I was able to debug my C# dll from a C++ project in VS2008 by doing the following:
In the C++ project's properties, goto Configuration Properties -> Debugging. 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.
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. I tried several settings within Visual Studio on the C++ and C# side. Nothing helps until I tried manually launching the Debugger.
You can use
Debugger.Launch();
to manually start the Debugger on your 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++. 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. Then I was able to jump back and forth between them while debugging.

Unable to open a windows form during debugging in VS2010

I am debugging a windows application in visual studio 2010, the application was developed and upgraded from .net framework v2 and VS 2005.
Originally, windows forms could be open on debugging mode. However, several times later without editing (as I was just tracking possible bugs before fixing), those forms become unable to open. Whenever, I tracked the bugs until the code which shows the form, then the debugger will just stop tracking without any messages. Does anyone know what problems could cause this situation? Thanks a lot.
Usually if you are unable to debug step into code then this usually indicates that there is no debug information available due to missing source and/or a missing debug .pdb file for that item.
Check the build configuration to ensure that you are attempting to debug a debug build, it is easy with solutions containing multiple projects to accidentally set the configuration manager to build a project in release mode, whilst the project that you're stepping from is in debug mode.
Also in multi-project solutions check that you are referencing the project and not the project output where required, otherwise setting the configuration manager to build a project in debug mode will have no effect if you're referencing a release build output for that project.
If the Winforms reside in a third party DLL then ensure that you have referenced a debug version of the library before attempting to debug.

Categories

Resources