Aspnetcore: In Blazor App Client don't find "@using Microsoft.AspNetCore.Components.Authorization"

Created on 5 Sep 2019  路  10Comments  路  Source: dotnet/aspnetcore

Describe the bug

In project Blazor Client ( TargetFramework netstandard2.0) with
PackageReference Include="Microsoft.AspNetCore.Authorization" Version="3.0.0-preview9.19424.4"
dont't find AuthenticationStateProvider => don't see namespace Microsoft.AspNetCore.Components.Authorization

if I change TargetFramework to netcoreapp3.0
I see namespace Microsoft.AspNetCore.Components.Authorization

To Reproduce

I created new simple project Blazor WebAssebly App
added Microsoft.AspNetCore.Authorization

> <Project Sdk="Microsoft.NET.Sdk.Web">
> 
>   <PropertyGroup>
>     <TargetFramework>netstandard2.0</TargetFramework>
>     <OutputType>Exe</OutputType>
>     <LangVersion>7.3</LangVersion>
>     <RazorLangVersion>3.0</RazorLangVersion>
>   </PropertyGroup>
> 
>   <ItemGroup>
>     <PackageReference Include="Microsoft.AspNetCore.Authorization" Version="3.0.0-preview9.19424.4" />
>     <PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4" />
>     <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
>     <PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19424.4" />
>     <PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
>   </ItemGroup>
> 
> </Project>
  1. See error
    @using Microsoft.AspNetCore.Components.Authorization show red

Error CS0234 The type or namespace name 'Authorization' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) BlazorAppClient5 C:\Users\袩芯谢褜蟹芯胁邪褌械谢褜\source\repos\BlazorAppClient5\BlazorAppClient5_Imports.razor

area-blazor

Most helpful comment

Try adding the reference explicitly using
Install-Package Microsoft.AspNetCore.Components.Authorization -Version 3.0.0-preview9.19424.4

All 10 comments

I second this one. I was using AuthenticationStateProvider fine on P8 yesterday morning.
P9 broke it.

Creating client-side and server-side default apps and adding an @import to the MainLayout.razor file. I browsed all the available namespaces on the client-side app and could not find the AuthenticationStateProvider class but on the server-side app, it is found in the Microsoft.AspNetCore.Components.Authorization namespace.

This namespace does not exist on the client-side app.

The server-side csproj file refers to the target framework netcoreapp3.0 with no additional project references.

The client-side csproj file refers to target framework netstandard2.0 and the project references

  • "Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4"
  • "Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19424.4" PrivateAssets="all"
  • "Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19424.4"
  • "Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19424.4" PrivateAssets="all"

Is it still possible for client-side developers to get access to the Microsoft.AspNetCore.Components.Authorization namespace?

Try adding the reference explicitly using
Install-Package Microsoft.AspNetCore.Components.Authorization -Version 3.0.0-preview9.19424.4

Thanks! That worked!

thanks, it works for me !

Thanks @ghidello.
We will include this in the migration guide to help the rest of the community with this.
/cc @danroth27

These aren't showing in the VS nuget feed at least at the time of this post.
image

It is in there, but the updated NuGet search puts it way back... The easiest is to add it manually into the csproj.

With NuGet search if you want to search by package ID you can add the "packageid:" prefix. See https://github.com/aspnet/AspNetCore/issues/13499#issuecomment-525896607.

That updated NuGet search is awful... who the heck thought exact matches shouldn't show up first?!

Weird thing is it builds fine on local machine, but not on build server -- that's frustrating... but more frustrating is that NuGet search (agree @MV10)!!!!!! It's like they put in the most intelligent contextual search system they possibly could... then accidentally listed it backwards.

Was this page helpful?
0 / 5 - 0 ratings