Skip to content
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

Compatibility issue with .Net Core 2.2.0 #19

Open
fschlaef opened this issue Dec 6, 2018 · 5 comments · May be fixed by #22
Open

Compatibility issue with .Net Core 2.2.0 #19

fschlaef opened this issue Dec 6, 2018 · 5 comments · May be fixed by #22

Comments

@fschlaef
Copy link

fschlaef commented Dec 6, 2018

When attempting to use this package on ASP.Net Core 2.2.0, I get the following exception at startup :

System.InvalidOperationException: Cannot use 'AspNetCore.RouteAnalyzer.Inner.Router' with Endpoint Routing.
   at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
   at Application.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime) in C:\me\Startup.cs:line 203
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Internal.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter.<>c__DisplayClass4_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

This only happends when using MVC compatibility version 2.2 in ConfigureServices :

services.AddMvc()
     .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)

The only workaround I found is to rollback to 2.1 compatibility mode :

services.AddMvc()
     .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)

However this prevents from benefiting from 2.2.0 improvements, and as such it is not a real workaround.

@anewton
Copy link

anewton commented Dec 16, 2018

Confirmed the repro steps for this issue. Also located v2.2.0 source code with the corresponding error message. https://github.com/aspnet/AspNetCore/blob/a07be530331ef6c4d9c1765b50c2a9d38268113c/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs

They have limited the allowed type inside the UseMvc method when evaluating the routes to be only Microsoft.AspNetCore.Routing.Route.

I may try a pull request on this issue after attempting a fix. Need to pull down the relevant sources and see if anything can be done with the inheritance on the route analyzer type. (Because this little library is pretty useful). If I don't get the pull request done, perhaps the author can take a look too.

@anewton
Copy link

anewton commented Dec 16, 2018

Here is my attempt at fixing this. The correct branch to look at is "release/2.2" in the code linked above. It seems all that would be needed is to construct a Router object in the method RouteAnalyzerRouteBuilderExtensions in this library. However, when I attempted it, the "/routes" route could not be found. The exception didn't happen. But the route wasn't constructed properly. Here's the code snippet I tried (commented out line and extra IServerProver parameter what what I changed).

public static class RouteAnalyzerRouteBuilderExtensions
{
    public static string RouteAnalyzerUrlPath { get; private set; } = "";

    public static IRouteBuilder MapRouteAnalyzer(this IRouteBuilder routes, string routeAnalyzerUrlPath, IServiceProvider serviceProvider)
    {
        var inlineConstraintResolver = serviceProvider.GetRequiredService<IInlineConstraintResolver>();
        RouteAnalyzerUrlPath = routeAnalyzerUrlPath;

        routes.Routes.Add(new Router(routes.DefaultHandler, routeAnalyzerUrlPath));
        //routes.Routes.Add(new Microsoft.AspNetCore.Routing.Route(new Router(routes.DefaultHandler, routeAnalyzerUrlPath), routeAnalyzerUrlPath, inlineConstraintResolver));
        return routes;
    }
}

nicolaspierre1990 added a commit to nicolaspierre1990/AspNetCore.RouteAnalyzer that referenced this issue Dec 19, 2018
nicolaspierre1990 added a commit to nicolaspierre1990/AspNetCore.RouteAnalyzer that referenced this issue Dec 19, 2018
@nicolaspierre1990 nicolaspierre1990 linked a pull request Dec 19, 2018 that will close this issue
@niconico49
Copy link

I Have exactly the same error with Net Core 3
Any intention to support that version?

Can somebody help me to understand and solve the problem?

Thanks

@ddagsan
Copy link

ddagsan commented Apr 5, 2019

I have the same issue.

@jlchavez
Copy link

jlchavez commented Aug 2, 2019

No official release on Nuget.org yet with this "fix"...

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

Successfully merging a pull request may close this issue.

5 participants