0
votes

I need to create an IAuthorizationFilter in my application, which is targeting .NET Core 3.0.

I needed a reference to Microsoft.AspNetCore.Http.DefaultHttpContext. That lives in the Microsoft.AspNetCore.Http namespace.

When I added the NuGet for Microsoft.AspNetCore.Http, I got an error saying that assembly 'Microsoft.AspNetCore.Mvc.Abstractions' with version 3.0.0.0 conflicted with 'Microsoft.AspNetCore.Http.Abstractions' with version 2.2.0.0.

When I looked, the NuGet I installed was version 2.2.0. But the problem is that there is not one for version 3.0 on NuGet.

How can I get a reference to Microsoft.AspNetCore.Http.DefaultHttpContext using .NET Core 3.0?

3
Which template type are using for your project? - Muhammad Hannan
The Microsoft.AspNetCore.* are referenced automatically now when your target framework is netcoreapp3.0. You will also need to make sure you are not referencing Microsoft.AspNetCore.App in you project file any longer. Unless you are using Razor pages, then you will need a Framework Reference to Microsoft.AspNetCore.App instead of a Package Reference. See: docs.microsoft.com/en-us/aspnet/core/migration/22-to-30 - Chris Stillwell

3 Answers

4
votes

You need to add a framework reference to asp.net core. See the migration guide docs for details See the migration guide docs for details

0
votes

I had to add a normal assembly reference to Microsoft.AspNetCore.Http.Abstractions and Microsoft.AspNetCore.Mvc.Abstractions.

I also needed to add the NuGet Package Microsoft.AspNetCore.Http.Features.

0
votes

Replace

<PackageReference Include="Microsoft.AspNetCore.Http" Version="..." />

With

<FrameworkReference Include="Microsoft.AspNetCore.App" />

in your csproj. See docs

and

A large number of NuGet packages aren't produced for ASP.NET Core 3.0. Such package references should be removed from your project file.

from migration guide

This is needed for all these packages:

  • Microsoft.AspNetCore
  • Microsoft.AspNetCore.All
  • Microsoft.AspNetCore.App
  • Microsoft.AspNetCore.Antiforgery
  • Microsoft.AspNetCore.Authentication
  • Microsoft.AspNetCore.Authentication.Abstractions
  • Microsoft.AspNetCore.Authentication.Cookies
  • Microsoft.AspNetCore.Authentication.Core
  • Microsoft.AspNetCore.Authentication.OAuth
  • Microsoft.AspNetCore.Authorization.Policy
  • Microsoft.AspNetCore.CookiePolicy
  • Microsoft.AspNetCore.Cors
  • Microsoft.AspNetCore.Diagnostics
  • Microsoft.AspNetCore.Diagnostics.HealthChecks
  • Microsoft.AspNetCore.HostFiltering
  • Microsoft.AspNetCore.Hosting
  • Microsoft.AspNetCore.Hosting.Abstractions
  • Microsoft.AspNetCore.Hosting.Server.Abstractions
  • Microsoft.AspNetCore.Http
  • Microsoft.AspNetCore.Http.Abstractions
  • Microsoft.AspNetCore.Http.Connections
  • Microsoft.AspNetCore.Http.Extensions
  • Microsoft.AspNetCore.HttpOverrides
  • Microsoft.AspNetCore.HttpsPolicy
  • Microsoft.AspNetCore.Identity
  • Microsoft.AspNetCore.Localization
  • Microsoft.AspNetCore.Localization.Routing
  • Microsoft.AspNetCore.Mvc
  • Microsoft.AspNetCore.Mvc.Abstractions
  • Microsoft.AspNetCore.Mvc.Analyzers
  • Microsoft.AspNetCore.Mvc.ApiExplorer
  • Microsoft.AspNetCore.Mvc.Api.Analyzers
  • Microsoft.AspNetCore.Mvc.Core
  • Microsoft.AspNetCore.Mvc.Cors
  • Microsoft.AspNetCore.Mvc.DataAnnotations
  • Microsoft.AspNetCore.Mvc.Formatters.Json
  • Microsoft.AspNetCore.Mvc.Formatters.Xml
  • Microsoft.AspNetCore.Mvc.Localization
  • Microsoft.AspNetCore.Mvc.Razor
  • Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
  • Microsoft.AspNetCore.Mvc.RazorPages
  • Microsoft.AspNetCore.Mvc.TagHelpers
  • Microsoft.AspNetCore.Mvc.ViewFeatures
  • Microsoft.AspNetCore.Razor
  • Microsoft.AspNetCore.Razor.Runtime
  • Microsoft.AspNetCore.Razor.Design
  • Microsoft.AspNetCore.ResponseCaching
  • Microsoft.AspNetCore.ResponseCaching.Abstractions
  • Microsoft.AspNetCore.ResponseCompression
  • Microsoft.AspNetCore.Rewrite
  • Microsoft.AspNetCore.Routing
  • Microsoft.AspNetCore.Routing.Abstractions
  • Microsoft.AspNetCore.Server.HttpSys
  • Microsoft.AspNetCore.Server.IIS
  • Microsoft.AspNetCore.Server.IISIntegration
  • Microsoft.AspNetCore.Server.Kestrel
  • Microsoft.AspNetCore.Server.Kestrel.Core
  • Microsoft.AspNetCore.Server.Kestrel.Https
  • Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions
  • Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
  • Microsoft.AspNetCore.Session
  • Microsoft.AspNetCore.SignalR
  • Microsoft.AspNetCore.SignalR.Core
  • Microsoft.AspNetCore.StaticFiles
  • Microsoft.AspNetCore.WebSockets
  • Microsoft.AspNetCore.WebUtilities
  • Microsoft.Net.Http.Headers