My fresh installed .NET Core Preview 8 don't find the Blazor LayoutAttribute i use the newest Templates and the newest Blazor Version:
any ideas what could be wrong???
I have gotten this issue as well.
Freshly updated to preview-8 and created a new project, all pages with a layout gets this error in the generated (*.g.razor) code.
The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components'
After some more investigation I found that this gives an error:
Microsoft.AspNetCore.Components.LayoutAttribute(...)
While these do not:
Layout(...)
LayoutAttribute(...)
Microsoft.AspNetCore.Components.Layouts.LayoutAttribute(...)
in other words, it's simply applying the wrong namespace. However, as these are generated files, knowing that doesn't really help me, as I am not familiar with how said files are actually generated.
Make sure you do not have Microsoft.AspNetCore.Components.Layouts referenced in your _Imports.razor file in the client project.
@gitasaurus Removing that reference does not solve the issue.
The error appears for _Imports
, Index
, and Counter
, and removing that line causes another error in MainLayout
. (all generated files *.razor.g.cs
)
The type or namespace name 'LayoutComponentBase' could not be found (are you missing a using directive or an assembly reference?)
Make sure you do not have Microsoft.AspNetCore.Components.Layouts referenced in your _Imports.razor file in the client project.
Its not solved it...
Update NuGet package Microsoft.AspNetCore.Blazor and Microsoft.AspNetCore.Blazor.Build.
i updated my nuget packages but its not working either..
I have gotten this issue as well.
Freshly updated to preview-8 and created a new project, all pages with a layout gets this error in the generated (*.g.razor) code.The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components'
After some more investigation I found that this gives an error:
Microsoft.AspNetCore.Components.LayoutAttribute(...)
While these do not:
Layout(...)
LayoutAttribute(...)
Microsoft.AspNetCore.Components.Layouts.LayoutAttribute(...)
in other words, it's simply applying the wrong namespace. However, as these are generated files, knowing that doesn't really help me, as I am not familiar with how said files are actually generated.
THIS is the Problem! but when you remove the Microsoft.AspNetCore.Components
it getting auto generated everytime and crash again
Have you installed the latest templates?
dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview8.19405.7
(see: https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-8/)
And try removing the previous templates: https://github.com/aspnet/AspNetCore/issues/12712#issuecomment-521084678
Thanks to the deleted comment which said to update NuGet packages, I did so, and it fixed the issue.
It appears as though I had two different copies of the Blazor WebAssembly Project
template, both of which were from preview6 (and also different from each other despite the same description?).
After deleting literally everything in /user/.templateengine (I hope that's not gonna come back and bite my behind) and installing the templates via the CLI, creating a new project works just fine.
Thanks to the deleted comment which said to update NuGet packages, I did so, and it fixed the issue.
It appears as though I had two different copies of theBlazor WebAssembly Project
template, both of which were from preview6 (and also different from each other despite the same description?).After deleting literally everything in /user/.templateengine (I hope that's not gonna come back and bite my behind) and installing the templates via the CLI, creating a new project works just fine.
i did everything you did but its not working...
i noticed that my client project is running on .netstandard 2.0 and GetJsonAsync
is also not found
@moritz-mm Is this on a new project? Which package version are the Asp.net packages?
In the project.csproj file there should be four packages like <PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview8.19405.7" />
(+.Build
.HttpClient
and .DevServer
)
Yes its a new Project.
Here is my .csproj file:
```
```
I had this same issue. I just created a video on building Blazor applications using Preview 7. The next day Preview 8 came out and my application had the errors specified above. There are multiple steps to fix this issue. You need to add two NuGet packages (Microsoft.AspNetCore.Blazor.DevServer and Microsoft.AspNetCore.Blazor.HttpClient), you need to change the OnInitAsync method name to OnInitializedAsync (if you were overriding them), and you need to remove the @using Microsoft.AspNetCore.Components.Layouts from your _Imports.razor page.
If you want to see that visually, I made a video of just upgrading my project to Preview 8: https://youtu.be/1-9dXoGl0Cg
I had this same issue. I just created a video on building Blazor applications using Preview 7. The next day Preview 8 came out and my application had the errors specified above. There are multiple steps to fix this issue. You need to add two NuGet packages (Microsoft.AspNetCore.Blazor.DevServer and Microsoft.AspNetCore.Blazor.HttpClient), you need to change the OnInitAsync method name to OnInitializedAsync (if you were overriding them), and you need to remove the @using Microsoft.AspNetCore.Components.Layouts from your _Imports.razor page.
If you want to see that visually, I made a video of just upgrading my project to Preview 8: https://youtu.be/1-9dXoGl0Cg
THANK YOU! This fixed it!
I had this same issue. I just created a video on building Blazor applications using Preview 7. The next day Preview 8 came out and my application had the errors specified above. There are multiple steps to fix this issue. You need to add two NuGet packages (Microsoft.AspNetCore.Blazor.DevServer and Microsoft.AspNetCore.Blazor.HttpClient), you need to change the OnInitAsync method name to OnInitializedAsync (if you were overriding them), and you need to remove the @using Microsoft.AspNetCore.Components.Layouts from your _Imports.razor page.
If you want to see that visually, I made a video of just upgrading my project to Preview 8: https://youtu.be/1-9dXoGl0Cg
THANK YOU! it's worked~
I had this same issue. I just created a video on building Blazor applications using Preview 7. The next day Preview 8 came out and my application had the errors specified above. There are multiple steps to fix this issue. You need to add two NuGet packages (Microsoft.AspNetCore.Blazor.DevServer and Microsoft.AspNetCore.Blazor.HttpClient), you need to change the OnInitAsync method name to OnInitializedAsync (if you were overriding them), and you need to remove the @using Microsoft.AspNetCore.Components.Layouts from your _Imports.razor page.
If you want to see that visually, I made a video of just upgrading my project to Preview 8: https://youtu.be/1-9dXoGl0Cg
I had this issue a few moments ago... Followed your steps and everything works. Thank you so much for sharing this with the community!
I got these errors just upgrading to VS Preview 2 while still on preview 7.
Not just OnInitAsync needs to be renamed, but also OnInit. Otherwise the above instructions got me working again. Thanks!
Another option is to check the breaking changes
https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-8/
I had this same issue. I just created a video on building Blazor applications using Preview 7. The next day Preview 8 came out and my application had the errors specified above. There are multiple steps to fix this issue. You need to add two NuGet packages (Microsoft.AspNetCore.Blazor.DevServer and Microsoft.AspNetCore.Blazor.HttpClient), you need to change the OnInitAsync method name to OnInitializedAsync (if you were overriding them), and you need to remove the @using Microsoft.AspNetCore.Components.Layouts from your _Imports.razor page.
If you want to see that visually, I made a video of just upgrading my project to Preview 8: https://youtu.be/1-9dXoGl0Cg
Thanks @TimCorey , really helpful video
Do you have some solve to Preview 7? because i don't want delete my Shared!
I get exactly the same issues upgrading to Preview 9. Have worked through the suggestions above but still get the following errors:
same here
I'm getting the same error for the RTM of VS 2019 community addition...
Most helpful comment
I had this same issue. I just created a video on building Blazor applications using Preview 7. The next day Preview 8 came out and my application had the errors specified above. There are multiple steps to fix this issue. You need to add two NuGet packages (Microsoft.AspNetCore.Blazor.DevServer and Microsoft.AspNetCore.Blazor.HttpClient), you need to change the OnInitAsync method name to OnInitializedAsync (if you were overriding them), and you need to remove the @using Microsoft.AspNetCore.Components.Layouts from your _Imports.razor page.
If you want to see that visually, I made a video of just upgrading my project to Preview 8: https://youtu.be/1-9dXoGl0Cg