All local variables show "Cannot obtain value of the local variable or argument (...)" in a WinUI 3 project using VS 2022

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.

Configuration Manager Example

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:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like