Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging symbols not loading in .NET standard project targeting .NET Framework

I am using Visual Studio 2017. I created a .NET Standard library (let this library be Lib1) project with two Target frameworks, netstandard2.0 and net46. Then I have another two projects... one is a "pure" .NET Framework 4.6 console project (lets call it Console46) and a .NET Core console project (lets call it ConsoleCore). Both of them reference Lib1.

When I run the ConsoleCore project, I can debug and put breakpoints without any problem, but when I run Console46, Visual Studio can not load the pdb file, so I can't debug the library, put breakpoints, etc.

I try to load the PDB file manually because it is created for the net46, but it fails also.

What can I do to fix this problem?

Thank you!

like image 288
jjamardo Avatar asked Jul 16 '18 14:07

jjamardo


People also ask

How do I load Debug symbols?

To specify symbol locations and loading options: In Visual Studio, open Tools > Options > Debugging > Symbols (or Debug > Options > Symbols).

How do I add Debug symbols in Visual Studio?

From Visual Studio, select Tools > Options > Debugging. Select Symbols from the list, and then select the + sign to add a new Azure DevOps symbol server location.

How do I Debug a .NET application in Visual Studio?

By default, Visual Studio Code launch settings use the Debug build configuration, so you don't need to change it before debugging. Start Visual Studio Code. Open the folder of the project that you created in Create a . NET console application using Visual Studio Code.


2 Answers

The answer @hans-passant posted in the comments is a good solution.

I rebuilt my .NET-Core libraries with this option in the csproj file. The following is a snippet that gets added to the csproj when you modify the file as per @hans-passant's instructions (Project > Properties > Build tab > Advanced button. Change the "Debugging information" combobox from Portable to Full):

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

I then dumped the built dll and pdb into the bin directory of my .NET-Framework application and I was able to step into my .NET-Core code.

like image 143
Daniel Avatar answered Oct 19 '22 00:10

Daniel


Here's a successful workaround for something very much similar to what you describe. When my 'Solution' contained only .NET Standard projects and I attempted to Debug using an external 4.6.1 Framework executable (let's call it "Foo.exe" from a separate solution) my breakpoints weren't hitting either.

My understanding is that there are two distinct debuggers, the .NET Core Debugger and the Full Framework Debugger. My vs 'Solution' defaulted to the former since that's the only type of Project that was in it.

What eventually worked for me was tricking VS2019 into using the Full Framework Debugger.

To do this, I added a placeholder 4.6.1 Framework console project to the solution and set it as the Startup project. In the Debug tab I set the Start Action exactly the same, pointing the value in Start External Program to the same one as before ("Foo.exe"). Now the breakpoints work.

NOTES for clarity:

  • The placeholder app doesn't do ANYTHING and is never ever actually run.
  • It doesn't need to reference the other .NET Standard assemblies that you're trying to debug.
  • The "Foo.exe" is the debugging process that gets attached in any case, but the breakpoints are only going to get hit when the Startup Project is a Framework project and NOT when the Startup Project is set to one of the .NET Standard projects in the same solution.

BTW setting the "Build\Advanced\Debugging information" to 'Full' as described in the earlier posts made no difference in my scenario but THANK YOU it made sense and was sure worth a try!

like image 35
IVSoftware Avatar answered Oct 19 '22 00:10

IVSoftware