简体   繁体   中英

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!

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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