runtime: Debugging not working with self-contained single file .NET6 assemblies
Description
When I publish a .NET assembly with the following command, there are no debug symbols available in VS2022. And trying to load the PDB manually leads to “image mismatch” errors or “can’t find matching debug symbols”.
This is the publish command:
dotnet publish -c Debug ./path/to/project.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r win-x64 --nologo --self-contained -o ./path/to/output
However if I set self-contained to false, it just works: --self-contained=false.
The problem occurs regardless if the debug symbols are embedded or stored as a PDB file.
I hope this is the right place. I know VS2022 is the one which can’t load the debug symbols but I am pretty sure it’s about the debug symbol creation/connection and not the loading. But I might be wrong.
Others seem to have the same problems. Look here: https://stackoverflow.com/questions/64897623/no-symbols-when-attaching-to-net-core-program-single-file/73796666#73796666.
Configuration
- dotnet 6 (but seems to be a problem since netcore already)
- tested on Win7 x64 but I guess the OS doesn’t matter here
- x64 in this case
- Debug config of course
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (10 by maintainers)
Disabled Just My Code it’s working now as expect. Sorry and thank you very much for your great help and time.
It should work with VS Community with no issues. Please try disabling Just My Code under Debug->Options.
Hope this helps!
You can use native AOT publish debug configuration:
Then similar to .NET core singlefile, drag the EXE into VS to create a VS project, then use the Native debug engine to debug (which I believe will be the default for this app type):
You should find that symbols load for the EXE and that you can set breakpoints in the program, view locals, and observe the callstack:
Note that the debug experience won’t be the same as .NET Core because the app has been compiled to native code, so things like C# expression evaluation and async stepping won’t work. Please see https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/diagnostics#native-debugging for more information.
Hope this helps!
I meant
System.Diagnostics.Debugger.IsAttacheddoes not return true if a native debugger is attached to the app.Thank you very much for your excellent explanation.
Do you mean System.Diagnostics.Debugger.IsAttached does not return true if a native debugger is attached to the app, or that you were not able to use the Managed (.NET Core, .NET 5+) debug engine with Native AOT? Note that Native AOT publish is off by default in VS and is only enabled if clicking the “Enable native AOT publish” option when creating the project:
When the publish for NativeAOT checkbox is set, the csproj will have the following line in it:
To use managed debugging on a published app, that line would need to be removed.
It’s possible to configure VS publishing to produce a single-file app:
Drag and drop the EXE into VS to create a VS EXE project:
Configure the Debugger engine for Managed (.NET Core, .NET 5+)
Then hit F10 to start the program with the instruction pointer in the first line in the program:
Yes:
One way is to use File->Open and navigate to the proper C# file and open it, then set a breakpoint at the desired location.
Another other way is to simply start the program with F10 (step) instead of F5 (go). F10 will start the program in the first line of the program.
And yet another way is to set a function breakpoint to stop in the desired function, automatically loading the sources for it. For example:
It sounds like the original problem reported in this issue is resolved, so I will go ahead and close this issue.
Hope this helps!!
no. it is not new. there are a lot of topics for 1-2 years
@VSadov I assume this is the new Windows API problems showing up