-
Notifications
You must be signed in to change notification settings - Fork 698
[WPF] VSCode shows error for WPF project: "The name 'InitializeComponent' does not exist in the current context (Roslyn CS0103) #5958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
same there |
@HyVong007 @heartacker A couple questions to help narrow down which component might be responsible. Are you using the prerelease C# extension (2.x)? Do you also have the C# DevKit extension installed? |
The first time i use C# dev kit (release) and C# (release) extensions => everything works fine ! Then C# Dev Kit shows me a notification that i must upgrade C# extension to pre-release version. After that, WPF has error "InitializeComponent does not exist......" |
I have the same errror after upgrade the C# extension to pre-release version. After I switch the c# extension to the release version the error disappeared. |
I have the same errror with C# Dev Kit v0.4.10. |
same issue. Any solution? |
Seeing the same error. Is there any workaround to fix this issue? Tried searching over the internet but all the answers there were related to this error occurring in Visual Studio and not Visual Studio Code. |
Same issue, |
same for me. i already tried using omnisharp and preview versions and the dev toolkit, it's all the same. also no autocomplete for XAML but this might be another typic/plugin |
I have the same issue, the wpf project can run normally, but vscode seems to be unable to associate xaml with xaml.cs properly, which is not an issue in Visual Studio |
Has anyone solved this problem? My OCD is acting up. |
I have the same. |
Still seeing this issue with C# version v2.14.8 and C# Dev Kit v1.1.16. Everything builds and runs OK but the error is still there. Any guidance at this point? |
I am seeing this same thing. Project builds in Visual Studio but in vscode it says InitializeCompnent() doesn't exist. (I should add this is a net472 sdk project) The C# dev kit release and pre-release show this for me. |
Still broken, it has been months. |
I am also seeing the same symptoms. It affects the hot reload functionality since an error is detected. You are then forced to stop the debugger and rebuild your project. Note that these errors are not preventing the building or running of the solution from scratch. To temporarily resolve the issue, this is what worked for me.
Hope this temporary fix assists, but we really do need a permanent solution. |
@Brentec-ca we're not talking about Visual Studio here but rather Visual Studio code but I know what you are talking about. When I was inserting one custom control it didn't want to build this in znak designer but cleaning .vs folder, running dotnet clean and then rebuild fixes the issue |
Guys, delete "obj" folder of your application. Then rebuild, this will fix that. Visual Studio fix tho. |
@PuR0kY as you may have noticed we are talking about vs code extension here. What you're mentioning in VS is a completely separate thing |
@marcin-przywoski Yeah surely, I just had this issue with Visual Studio too, so thought would be nice to mention here. If not. I can delete it no without any problem. |
I'm seeing the same issue with
The strange thing is that this isn't preventing me from running my application. |
Same here over multiple projects all working fine. A way to hide the error would be good too. |
We're not talking about visual studio, we're talking about vs code |
It works on my VS, thanks. |
I have the same issue with VS Code. As soon as I ran But if I perform |
To all the people suffering from this problem: <ItemGroup>
<Compile Include="obj/Debug/net8.0-windows/*.cs">
<AutoGen>True</AutoGen>
</Compile>
</ItemGroup> Edit:The path should be where the (If that doesn't work, maybe you can try replacing |
@aianlinb didn't work for me :/ even after I changed the path in Include to the matching one in my project |
Unfortunately this didn't work for me. |
@marcin-przywoski @codenotworking I edited some messages above, maybe try it again. wish good luck |
This works for me, it helps bro, thanks. Seems like Visual Studio does something for the generated build, but the vscode extension does not, so it should be done manually. |
The DevKit tracking issue for this bug is microsoft/vscode-dotnettools#1018 |
But, This make xUnit Test Explorer is disable. This is fine because you can run it with dotnet cli. BTW, is there no similar bug in MAUI? |
<ItemGroup>
<Compile Update="obj/Debug/net8.0-windows/*.cs">
<AutoGen>True</AutoGen>
</Compile>
<Compile Update="obj/Win32/Debug/net8.0-windows/*.cs">
<AutoGen>True</AutoGen>
</Compile>
</ItemGroup> |
I unchecked the Dotnet: Prefer CSharp Extension, but it appears to have also disabled the build button in the IDE. I can still run the app from the command line via |
Confirming that adding However, this feels like a temporary remedy rather than a proper solution. Relying on this setting effectively disables the primary C# Dev Kit ( Ideally, the C# Dev Kit language server should be able to reliably locate and parse the generated
This would allow developers to use the full capabilities of the C# Dev Kit while still getting correct IntelliSense for WPF projects. |
The C# Dev Kit side issue is tracked here - microsoft/vscode-dotnettools#1018 |
1/ Install .NET Core 7.0
2/ Create WPF project with "dotnet new wpf"
3/ VSCode > Open Folder.
After awhile, VSCode shows many errors:
"The name 'InitializeComponent' does not exist in the current context"
Moreover, any variables declared in .XAML file will cause error if these variables are used in .CS file
Hope VSCode Dev Team will fix bugs soon, thank you very much !
The text was updated successfully, but these errors were encountered: