c# – ASP.NET Core Paging – PagedList.Core

Question:

I'm creating an ASP.NET core study project, and when using the PagedList.Core paging library, I PagedList.Core getting the following error when running the dotnet run command:

Startup.cs(49,35): error CS0246: Type or namespace name "IActionContextAccessor" cannot be found (Is using directive or assembly reference missing?) [C:\projects\net\osnet\osnet .csproj]
Startup.cs(49,59): error CS0246: Type or namespace name "ActionContextAccessor" cannot be found (is using directive or assembly reference missing?) [C:\projects\net\osnet\osnet .csproj]

Build failure occurred. Fix build errors and rerun.

What could it be ?

My ConfigureServices method from the Startup.cs file looks like this:

public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
       
        var connection = Configuration["ConexaoSqlite:SqliteConnectionString"];
        services.AddDbContext<OsNetContext>(options =>
            options.UseSqlite(connection)
        );
        // Add framework services.
        services.AddMvc();
        services.AddSingleton<IActionContextAccessor, ActionContextAccessor>(); // <= Add this
        
    }

Answer:

Make sure your project is referencing the Microsoft.AspNetCore.Mvc.Core.dll assembly

The interface namespace is Microsoft.AspNetCore.Mvc.Infrastructure

Scroll to Top
AllEscort