Microsoft.Aspnetcore.Authorization namespace is missing with .NET Core 2.2
See original GitHub issueMicrosoft.Aspnetcore.Authorization namespace is missing when using .NET Core 2.2
To Reproduce
- Set TargetFramework of .csproj file to “netcoreapp2.2”
- Set RuntimeFrameworkVersion to “2.2.0”
- Include PackageReference “Microsoft.AspNetCore.App”
- Try to use Authorize attribute or to Microsoft.AspNetCore.Authorization namespace in any controller.
- Namespace is not found.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RuntimeFrameworkVersion>2.2.0</RuntimeFrameworkVersion>
<DebugType>Full</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>
</Project>
Expected behavior Running the same project with net core 2.1 works fine. Tried to include Microsoft.AspNetCore.Authorization package explicitly using nuget with no success. Error appears to be the same.
Screenshots
Desktop:
- OS: Windows 10 x64
- IDE: Visual Studio 15.9.3
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Microsoft.Aspnetcore.Authorization namespace is missing ...
AspNetCore.Authorization namespace in any controller. Namespace is not found. ... Running the same project with net core 2.1 works fine. Tried to ...
Read more >Error CS0234: The type or namespace name 'AspNetCore ...
Error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Read more >Migrate from ASP.NET Core 2.2 to 3.0
Learn how to migrate an ASP.NET Core 2.2 project to ASP. ... if an authorization or CORS policy is skipped due to missing...
Read more >Microsoft.AspNetCore.Authorization Namespace
Contains types that enable support for authorization. The main types are IAuthorizationRequirement (marker interface representing a requirement which must ...
Read more >ASP.NET Core breaking changes for versions 3.0 and 3.1
Lists the breaking changes in ASP.NET Core 3.0 and 3.1. ... NET Core 2.2, follow the guidance in the obsolete build messages to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just had this same exact issue pop-up again, but this time with the
Microsoft.AspNetCore.Authentication.Cookies
package.I installed this package to my project using
Install-Package Microsoft.AspNetCore.Authentication.Cookies -Version 2.2.0
. After doing that, I still could not reference it in my project. When I highlighted the dependency in my project and looked at the properties, I saw the Path for that package was set toC:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.authentication.cookies\2.2.0
I went in and removed the entire folder
C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.authentication.cookies
and then did a package restore in VS. After doing this, I noticed it updated the Path toC:\Users\<my user name>\.nuget\packages\microsoft.aspnetcore.authentication.cookies\2.2.0
.I then rebuilt the project and everything worked. I can now reference
Microsoft.AspNetCore.Authentication.Cookies
.I would not be surprised if this was the same issue.
Thanks for the extra info @jonnale . It’s not clear to us the exact cause for this but if anyone has exact steps to reproduce this problem, please upload your project to a GitHub repo with instructions on what to install, what to run, etc., and we can try to investigate more. In the meantime I’m closing this issue because there’s no immediate action for us to take here.