In Maui 'InitializeComponent()' does not exist in the current context.
Intro (not must read)
I use Visual Studio 2022LTS regularly . It happens to install Preview version, and the IDE says usualy "'InitializeComponent()' does not exist in the current context.". However, it also says
NETSDK1147 if you want to build this project, you need installing these workload wasi-experimental. Run this command for installing dotnet workload restore .
I translated error massages from Japanese to English that’s why sentences is not accurate, But I searched and understand that means workload for Maui and SDK were not installed to my visual studio.
I have tried below solutions then errors purged, so I noted this page.
OutLine
In Maui, I built project for debugging Error List tell me that
-
'InitializeComponent()' does not exist in the current context.
I tried these steps
- Reboot PC
-
Reinstalled VisualStudio and VisualStudio installer
- Installed must have workloads via VisualStudio installer
- Rebuilt the project
- Checked build action at ContentPage is MauiXaml
My environment
-
date 2024/07/21
-
Visual Studio 2022 version 17.10.4 PRE
-
Maui
- CommunityToolkit MVVM
My Solution
- Open command-line tool from tool tab
- Execute this 「dotnet workload restore」
- After in stalled them, also execute 「dotnet workload install maui」
- Reboot your PC after save all
- Check resolve or not in same project
Otheres(not must read)
Have you solve the error?
This can be unique situation in my environment, so if you have any solution or matter please comment . Thank you for reading.