-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Blank MAUI shows CS0103 "The name 'InitializeComponent' does not exist in the current context" #4098
Labels
area-tooling
XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging
area-xaml
XAML, CSS, Triggers, Behaviors
fixed-in-6.0.200-preview.13.2
Look for this fix in 6.0.200-preview.13.2!
t/bug
Something isn't working
Comments
So far the logs from MSBuild give us:
No other errors in the log. Next steps, I'm getting further instructions on debugging MSBuild... |
jonathanpeppers
added a commit
to jonathanpeppers/maui
that referenced
this issue
Jan 13, 2022
The source generator was doing: using (var reader = File.OpenText(projItem.AdditionalText.Path)) The problem with this, is you don't actually have to hit Ctrl+S in Visual Studio to save the files. This is potentially loading stale files on disk. Instead we can use: projItem.AdditionalText.GetText().ToString(); And this will give us the string contents of the file from the in-memory Roslyn state. This might solve some of the weird issues in the IDE such as: dotnet#4098 However, I'm still able to reproduce dotnet#4098 after making this change.
12 tasks
Redth
pushed a commit
that referenced
this issue
Jan 13, 2022
The source generator was doing: using (var reader = File.OpenText(projItem.AdditionalText.Path)) The problem with this, is you don't actually have to hit Ctrl+S in Visual Studio to save the files. This is potentially loading stale files on disk. Instead we can use: projItem.AdditionalText.GetText().ToString(); And this will give us the string contents of the file from the in-memory Roslyn state. This might solve some of the weird issues in the IDE such as: #4098 However, I'm still able to reproduce #4098 after making this change.
We found unchecking this setting solves this problem: But I also have the changes from #4128 locally. The Roslyn team is investigating. |
jonathanpeppers
added a commit
to jonathanpeppers/maui
that referenced
this issue
Jan 20, 2022
Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138 Fixes: dotnet#4098 This partially reverts 974cac4. Creating a new MAUI solution, results in several intellisense errors: CS0103: The name 'InitializeComponent` does not exist in the current context. The missing members are created by the (previously XamlG) Roslyn source generator. You can go-to definition the missing members, build & run works, and if you close/reopen the solution the errors go away. Unchecking the `Run code analysis in a separate process`, also seems to solve the issue. .NET MAUI seems to be using an intersection of features that causes this problem: 1. We have a `dotnet new maui` project template. 2. We have a source generator in a NuGet package. 3. We have MSBuild targets that setup the source generator in a NuGet package. 4. We use `AdditionalFiles` to pass `.xaml` files in to the source generator. What happens on the first project load, the design-time builds *before* project restore are missing the source generator. So the call to `<Csc/>` does not have `@(Analyzer)` or `AdditionalFiles` at all. To solve this issue, we can move everything *out* of NuGet packages, so they become regular "SDK" or workload packs: * `Microsoft.Maui.Controls.Build.Tasks` is no longer packable * all files moved to `Microsoft.Maui.Sdk` * `Resizetizer.csproj` is no longer packable * actual files are in `Microsoft.Maui.Resizetizer.Sdk` * `$(MauiVersion)` no longer applies to build tasks Testing locally, this seems to solve the problem for me. I can see the `@(Analyzer)` and `AdditionalFiles` being passed on all design-time builds now. Other changes: * I added `%(IsImplicitlyDefined)` to the source generator assembly. I just noticed this was missing while reading `.binlog` files. * I put all files in the `Sdk` folder in `Microsoft.Maui.Sdk`. This seems a bit simpler to have one directory.
12 tasks
jonathanpeppers
added a commit
to jonathanpeppers/maui
that referenced
this issue
Jan 20, 2022
Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138 Fixes: dotnet#4098 This partially reverts 974cac4. Creating a new MAUI solution, results in several intellisense errors: CS0103: The name 'InitializeComponent` does not exist in the current context. The missing members are created by the (previously XamlG) Roslyn source generator. You can go-to definition the missing members, build & run works, and if you close/reopen the solution the errors go away. Unchecking the `Run code analysis in a separate process`, also seems to solve the issue. .NET MAUI seems to be using an intersection of features that causes this problem: 1. We have a `dotnet new maui` project template. 2. We have a source generator in a NuGet package. 3. We have MSBuild targets that setup the source generator in a NuGet package. 4. We use `AdditionalFiles` to pass `.xaml` files in to the source generator. What happens on the first project load, the design-time builds *before* project restore are missing the source generator. So the call to `<Csc/>` does not have `@(Analyzer)` or `AdditionalFiles` at all. To solve this issue, we can move everything *out* of NuGet packages, so they become regular "SDK" or workload packs: * `Microsoft.Maui.Controls.Build.Tasks` is no longer packable * all files moved to `Microsoft.Maui.Sdk` * `Resizetizer.csproj` is no longer packable * actual files are in `Microsoft.Maui.Resizetizer.Sdk` * `$(MauiVersion)` no longer applies to build tasks Testing locally, this seems to solve the problem for me. I can see the `@(Analyzer)` and `AdditionalFiles` being passed on all design-time builds now. Other changes: * I added `%(IsImplicitlyDefined)` to the source generator assembly. I just noticed this was missing while reading `.binlog` files. * I put all files in the `Sdk` folder in `Microsoft.Maui.Sdk`. This seems a bit simpler to have one directory.
jonathanpeppers
added a commit
to jonathanpeppers/maui
that referenced
this issue
Jan 20, 2022
Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138 Fixes: dotnet#4098 This partially reverts 974cac4. Creating a new MAUI solution, results in several intellisense errors: CS0103: The name 'InitializeComponent` does not exist in the current context. The missing members are created by the (previously XamlG) Roslyn source generator. You can go-to definition the missing members, build & run works, and if you close/reopen the solution the errors go away. Unchecking the `Run code analysis in a separate process`, also seems to solve the issue. .NET MAUI seems to be using an intersection of features that causes this problem: 1. We have a `dotnet new maui` project template. 2. We have a source generator in a NuGet package. 3. We have MSBuild targets that setup the source generator in a NuGet package. 4. We use `AdditionalFiles` to pass `.xaml` files in to the source generator. What happens on the first project load, the design-time builds *before* project restore are missing the source generator. So the call to `<Csc/>` does not have `@(Analyzer)` or `AdditionalFiles` at all. To solve this issue, we can move everything *out* of NuGet packages, so they become regular "SDK" or workload packs: * `Microsoft.Maui.Controls.Build.Tasks` is no longer packable * all files moved to `Microsoft.Maui.Sdk` * `Resizetizer.csproj` is no longer packable * actual files are in `Microsoft.Maui.Resizetizer.Sdk` * `$(MauiVersion)` no longer applies to build tasks Testing locally, this seems to solve the problem for me. I can see the `@(Analyzer)` and `AdditionalFiles` being passed on all design-time builds now. Other changes: * I added `%(IsImplicitlyDefined)` to the source generator assembly. I just noticed this was missing while reading `.binlog` files. * I put all files in the `Sdk` folder in `Microsoft.Maui.Sdk`. This seems a bit simpler to have one directory.
jonathanpeppers
added a commit
to jonathanpeppers/maui
that referenced
this issue
Jan 20, 2022
Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138 Fixes: dotnet#4098 This partially reverts 974cac4. Creating a new MAUI solution, results in several intellisense errors: CS0103: The name 'InitializeComponent` does not exist in the current context. The missing members are created by the (previously XamlG) Roslyn source generator. You can go-to definition the missing members, build & run works, and if you close/reopen the solution the errors go away. Unchecking the `Run code analysis in a separate process`, also seems to solve the issue. .NET MAUI seems to be using an intersection of features that causes this problem: 1. We have a `dotnet new maui` project template. 2. We have a source generator in a NuGet package. 3. We have MSBuild targets that setup the source generator in a NuGet package. 4. We use `AdditionalFiles` to pass `.xaml` files in to the source generator. What happens on the first project load, the design-time builds *before* project restore are missing the source generator. So the call to `<Csc/>` does not have `@(Analyzer)` or `AdditionalFiles` at all. To solve this issue, we can move everything *out* of NuGet packages, so they become regular "SDK" or workload packs: * `Microsoft.Maui.Controls.Build.Tasks` is no longer packable * all files moved to `Microsoft.Maui.Sdk` * `Resizetizer.csproj` is no longer packable * actual files are in `Microsoft.Maui.Resizetizer.Sdk` * `$(MauiVersion)` no longer applies to build tasks Testing locally, this seems to solve the problem for me. I can see the `@(Analyzer)` and `AdditionalFiles` being passed on all design-time builds now. Other changes: * I added `%(IsImplicitlyDefined)` to the source generator assembly. I just noticed this was missing while reading `.binlog` files. * I put all files in the `Sdk` folder in `Microsoft.Maui.Sdk`. This seems a bit simpler to have one directory.
jonathanpeppers
added a commit
to jonathanpeppers/maui
that referenced
this issue
Jan 20, 2022
Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138 Fixes: dotnet#4098 This partially reverts 974cac4. Creating a new MAUI solution, results in several intellisense errors: CS0103: The name 'InitializeComponent` does not exist in the current context. The missing members are created by the (previously XamlG) Roslyn source generator. You can go-to definition the missing members, build & run works, and if you close/reopen the solution the errors go away. Unchecking the `Run code analysis in a separate process`, also seems to solve the issue. .NET MAUI seems to be using an intersection of features that causes this problem: 1. We have a `dotnet new maui` project template. 2. We have a source generator in a NuGet package. 3. We have MSBuild targets that setup the source generator in a NuGet package. 4. We use `AdditionalFiles` to pass `.xaml` files in to the source generator. What happens on the first project load, the design-time builds *before* project restore are missing the source generator. So the call to `<Csc/>` does not have `@(Analyzer)` or `AdditionalFiles` at all. To solve this issue, we can move everything *out* of NuGet packages, so they become regular "SDK" or workload packs: * `Microsoft.Maui.Controls.Build.Tasks` is no longer packable * all files moved to `Microsoft.Maui.Sdk` * `Resizetizer.csproj` is no longer packable * actual files are in `Microsoft.Maui.Resizetizer.Sdk` * `$(MauiVersion)` no longer applies to build tasks Testing locally, this seems to solve the problem for me. I can see the `@(Analyzer)` and `AdditionalFiles` being passed on all design-time builds now. Other changes: * I added `%(IsImplicitlyDefined)` to the source generator assembly. I just noticed this was missing while reading `.binlog` files. * I put all files in the `Sdk` folder in `Microsoft.Maui.Sdk`. This seems a bit simpler to have one directory.
Redth
pushed a commit
that referenced
this issue
Jan 21, 2022
Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138 Fixes: #4098 This partially reverts 974cac4. Creating a new MAUI solution, results in several intellisense errors: CS0103: The name 'InitializeComponent` does not exist in the current context. The missing members are created by the (previously XamlG) Roslyn source generator. You can go-to definition the missing members, build & run works, and if you close/reopen the solution the errors go away. Unchecking the `Run code analysis in a separate process`, also seems to solve the issue. .NET MAUI seems to be using an intersection of features that causes this problem: 1. We have a `dotnet new maui` project template. 2. We have a source generator in a NuGet package. 3. We have MSBuild targets that setup the source generator in a NuGet package. 4. We use `AdditionalFiles` to pass `.xaml` files in to the source generator. What happens on the first project load, the design-time builds *before* project restore are missing the source generator. So the call to `<Csc/>` does not have `@(Analyzer)` or `AdditionalFiles` at all. To solve this issue, we can move everything *out* of NuGet packages, so they become regular "SDK" or workload packs: * `Microsoft.Maui.Controls.Build.Tasks` is no longer packable * all files moved to `Microsoft.Maui.Sdk` * `Resizetizer.csproj` is no longer packable * actual files are in `Microsoft.Maui.Resizetizer.Sdk` * `$(MauiVersion)` no longer applies to build tasks Testing locally, this seems to solve the problem for me. I can see the `@(Analyzer)` and `AdditionalFiles` being passed on all design-time builds now. Other changes: * I added `%(IsImplicitlyDefined)` to the source generator assembly. I just noticed this was missing while reading `.binlog` files. * I put all files in the `Sdk` folder in `Microsoft.Maui.Sdk`. This seems a bit simpler to have one directory.
Repository owner
moved this from In Progress
to Done
in [ARCHIVED] MAUI Planning
Jan 21, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area-tooling
XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging
area-xaml
XAML, CSS, Triggers, Behaviors
fixed-in-6.0.200-preview.13.2
Look for this fix in 6.0.200-preview.13.2!
t/bug
Something isn't working
Description
From: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1459138
When creating a new solution, often there are build errors referencing the XamlG (generated code behind for XAML).
Closing the solution and reopening usually makes the errors go away.
Related:
#3281
The text was updated successfully, but these errors were encountered: