After setting break points and trying to step through the values of variables in a WinUI 3 project, I'm getting the following:
Cannot obtain value of the local variable or argument because it is not available at this instruction pointer, possibly because it has been optimized away.
I'm seeing this for basically every local variable. I've searched for hours attempting to fix this but to no avail.
I'm running the project in Debug > x64 as a packaged app. Optimize code is turned off. JIT optimizations are also off. I'm using Windows 11 but it's also occurring on Windows 10. I'm using Visual Studio 2022 to debug. Is there something that I'm doing wrong?
2 Answers
Had the exact same thing. As a workaround I accepted that I can't debug when compiled natively, so I settled for a new 'Any CPU' platform assigned to the winui 3 app project itself. Then all debugging works again for me.
Note that this requires that you allow this in the project file, using the AllowNeutralPackageWithAppHost. Like this:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>WinExe</OutputType> : : snap : <AllowNeutralPackageWithAppHost>true</AllowNeutralPackageWithAppHost> : </PropertyGroup> So it turns out it was a bug with the WinUI 3 Template Studio. This has since been resolved, but if you are using a project created before the fix was integrated you can take a look at the github issue I submitted for the fix: