1

I have test .NET 5 WinForms application that references .NET Framework 4.8 class library - Github link.

I suppose it's possible because of .NET Framework compatibility mode

When I'm trying to debug a class library in Visual Studio 2019 16.8.4 (by starting my .NET 5 application) I get an error:

The debugger was configured to use the Desktop CLR (.NET Framework) Managed debugger, but the target process loaded the CoreCLR (.NET Core) runtime. The debugger was configured to use the Desktop CLR (.NETFramework) Managed debugger, but the target process loaded the CoreCLR (.Net Core) runtime. To debug this project, configure it to use the 'Managed (CoreCLR)' debugger.

enter image description here

Where can I find an option to use the 'Managed (CoreCLR)' debugger.

Thank you in advance.

UPDATE If I start debugging from .NET 5 application project - I can step into .NET Framework 4.8 class library. But I want to debug from class library project.

bairog
  • 3,143
  • 6
  • 36
  • 54
  • https://learn.microsoft.com/en-us/dotnet/standard/net-standard#net-implementation-support --> NET Framework doesn't support .NET Standard 2.1, i think coulden't work – Xilmiki Jan 25 '21 at 12:09
  • I know that .NET Framework 4.8 supports .NET Standart 2.0. But [.NET Framework compatibility mode](https://learn.microsoft.com/en-us/dotnet/core/porting/third-party-deps#net-framework-compatibility-mode) allows .NET Standard and .NET Core projects to reference .NET Framework libraries. – bairog Jan 25 '21 at 12:24
  • There seems to be no particular *need* to start from the class library, though. If you ensure the debugging symbols are accessible (possibly add the class library project to the solution of the application temporarily, possibly as a new solution) you can debug code in the library as you please. – Jeroen Mostert Jan 25 '21 at 12:50
  • @JeroenMostert Yes as I wrote in update I can debug from .NET 5 application project - debug symbols are accessible and I can step into class library code. But for some strange reason breakpoints in class library code are not working. So for me it would be more convenient to start from class library project. If it is possible of cource. – bairog Jan 25 '21 at 12:54
  • If breakpoints aren't working that suggests that there might be a mismatch in the symbol compatibility anyway -- check that your library is producing portable PDBs, even if being compiled as .NET Framework. Starting the debugger as Core but from the library project wouldn't fix this in and of itself. Worst case you'd need to rebuild the lib as Core. – Jeroen Mostert Jan 25 '21 at 12:57
  • @JeroenMostert `Starting the debugger as Core` - where I can find that option in VS 2019? – bairog Jan 25 '21 at 12:59
  • I have no idea or I'd tell you. :-) There may well not be such an option at all, I see no reason they'd add that to Framework projects since it wouldn't work most of the time. That the debugger tells you to do it doesn't mean VS can actually do it (you can probably do it if attaching to the process after the fact rather than right from the start). – Jeroen Mostert Jan 25 '21 at 13:01

1 Answers1

1

One useful function is to change your net framework project from non-sdk into new-sdk csproj format.

1) create a net core class library project and then enter its csproj file and then change the targetframework into:

<TargetFramework>net48</TargetFramework>

So you got a net framework4.8 project which is compatible with CoreCLR.

See this document.

When you finish it, please move your non-sdk net framework4.8 files into the new one.

2) use Attach to Process and it should has a execute program to run the code of the lib project.

You can check this issue to get the detailed steps, when you open Attach to Process and remember to choose Managed(.Net Core,NET5+) and that is the debugger.

enter image description here

This is a similar issue about it.

In fact, I recommend the solution one and solution two might have some small problems.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41