The error always appears in the generated file MainWindow.g.cs. This indicates that the XAML compiler is not correctly connecting the UI file to the code-behind file.
Troubleshooting Steps Already Taken:
I have already performed extensive troubleshooting, including:
Rebuilding the solution multiple times.
Cleaning the solution and manually deleting the bin, obj, and .vs folders.
Running dotnet restore from the Developer PowerShell.
Running the "Repair" feature from the Visual Studio Installer.
Performing a full factory reset of Windows and a fresh install.
After the factory reset, performing a fresh install of Visual Studio 2022 Community and also Visual Studio 2022 Preview.
During the installation, I selected the following workloads:
.NET desktop development
Universal Windows Platform development
Desktop development with C++
WinUI application development
The error persists even after a complete OS and Visual Studio reinstall, on both the stable and preview versions of Visual Studio. This seems to be a fundamental issue with the build tools or the SDK installation on my machine.
Any help would be greatly appreciated. Thank you.