Skip to content

[Help Needed] Endpoint Routing does not support 'IApplicationBuilder.UseMvc(...)'. To use 'IApplicationBuilder.UseMvc' set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices(...). #795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RichardsonWTR opened this issue Jul 30, 2020 · 3 comments

Comments

@RichardsonWTR
Copy link

RichardsonWTR commented Jul 30, 2020

Reproduce the issue

Fork it and reproduce the issue: Trying to use JADNC in a Web API with .net core 3.1. It's a very basic example.

Description

I was following the step-by-step guide, but I'm stuck in the method Configure in Startup.cs.
When app.UseJsonApi(); is called the following error is thrown:

System.InvalidOperationException
  HResult=0x80131509
  Message=Endpoint Routing does not support 'IApplicationBuilder.UseMvc(...)'. To use 'IApplicationBuilder.UseMvc' set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices(...).
  Source=Microsoft.AspNetCore.Mvc.Core
  StackTrace:
   at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
   at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app)
   at JsonApiDotNetCore.Extensions.IApplicationBuilderExtensions.UseJsonApi(IApplicationBuilder app, Boolean useMvc)
   at SIGN.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in Startup.cs:line 134
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.<StartAsync>d__31.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>d__9.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at SIGN.Program.Main(String[] args) in Program.cs:line 16

  This exception was originally thrown at this call stack:
	Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(Microsoft.AspNetCore.Builder.IApplicationBuilder, System.Action<Microsoft.AspNetCore.Routing.IRouteBuilder>)
	Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(Microsoft.AspNetCore.Builder.IApplicationBuilder)
	JsonApiDotNetCore.Extensions.IApplicationBuilderExtensions.UseJsonApi(Microsoft.AspNetCore.Builder.IApplicationBuilder, bool)
    SIGN.Startup.Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder, Microsoft.AspNetCore.Hosting.IWebHostEnvironment) in Startup.cs
	System.Reflection.RuntimeMethodInfo.Invoke(object, System.Reflection.BindingFlags, System.Reflection.Binder, object[], System.Globalization.CultureInfo)
	Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(object, Microsoft.AspNetCore.Builder.IApplicationBuilder)
	Microsoft.AspNetCore.Hosting.ConfigureBuilder.Build.AnonymousMethod__0(Microsoft.AspNetCore.Builder.IApplicationBuilder)
	Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup.AnonymousMethod__2(Microsoft.AspNetCore.Builder.IApplicationBuilder)
	Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.Configure.__MiddlewareFilterBuilder|0(Microsoft.AspNetCore.Builder.IApplicationBuilder)
    ...
    [Call Stack Truncated]

I didn't find anything on the docs mentioning about the need to use MVC. Is this a limitation?

Here is the some relevant piece of code:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<DatabaseContext>(options =>
        options.UseSqlServer(
            Configuration.GetConnectionString("DefaultConnection")));

    services.AddJsonApi<DatabaseContext>();

    services.AddControllers();

    services.AddCors(options =>
        // some configuration
    );
    // some other config..........
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseHttpsRedirection();

    app.UseRouting();
    app.UseJsonApi(); // error is thrown in this line.

    app.UseCors("default");

    app.UseAuthentication();
    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers()
                .RequireAuthorization();
    });
    // some other config..........
}

Any help would be appreciated.
Best regards.

Environment

  • JsonApiDotNetCore Version: 3.1.0
  • .Net Core Version: 3.1.101
@RichardsonWTR
Copy link
Author

I noticed something that could be related.
In the controller docs the controller has this signature:

public class PeopleController : JsonApiController<Person>
{
    public PeopleController(
        IJsonApiOptions jsonApiOptions,
        ILoggerFactory loggerFactory,
        IResourceService<Person> resourceService)
    : base(jsonApiOptions, loggerFactory, resourceService)
    { }
}

But when I was creating the project, IJsonApiOptions is not found.
So I got the code working when I changed to:

public sealed class PeopleController : JsonApiController<Person>
    {
        public PeopleController(
            IJsonApiContext jsonApiOptions,
            ILoggerFactory loggerFactory,
            IResourceService<Person> resourceService)
        : base(jsonApiOptions, resourceService, loggerFactory)
        { }
    }

Besides that, the base constructor also has a different signature, notice that resourceService changed its position with loggerFactory.
Maybe the docs is outdated? I'm lost here.
Any help would be appreciated.
Thanks in advance.

@bart-degreed
Copy link
Contributor

bart-degreed commented Aug 4, 2020

There's a community attempt to get JADNC v3.x running on .NET Core 3.1 that may help.

Though I would recommend to use the latest v4 prerelease instead, because 3.x is very old and a lot has changed since then. Release plans for v4 are tracked at #693. The published documentation is generated from the master branch, which contains v4.

Speaking for myself: I joined this project at a time that v4 was already in development. So I have never used JADNC v3.x and have no interest in doing any work on it.

@RichardsonWTR
Copy link
Author

It looks like I hadn't paid attention in the Compatibility section in the readme. My bad, sorry.
I'll take your advice in consideration. Thanks.
Thank you even more for your personal advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants