Last post Sep 26, 2019 07:41 PM by Shogun1972
Sep 25, 2019 09:36 PM|Shogun1972|LINK
I'm developing a .net core 2.2 razor pages app using visual studio 2019. All has been running fine, until this morning and now I get this seemingly random error:
InvalidOperationException: The constraint reference 'id' could not be resolved to a type. Register the constraint type with 'Microsoft.AspNetCore.Routing.RouteOptions.ConstraintMap'.
Microsoft.AspNetCore.Routing.DefaultParameterPolicyFactory.Create(RoutePatternParameterPart parameter, string inlineText)
The thing is that I haven't made any recent changes to the startup.cs routing options. And it doesn't matter what page I load, both pages requiring an id and those that don't require an id, all produce this error. Files in the wwwroot are accessible
via http, but any page in the PAGES folder produces the error.
When I run the app in VS2019 it compiles without error yet the browser displays this error above. I put a breakpoint in startup.cs. I can step into each sub and it completes without exception as if the app will load per usual. Then, voila... the above error
appears in the browser but the app is still running and active in VS.
I've done the obvious things, clean and rebuild project, reboot, etc. I also tested other projects which load up in VS and run fine, so it seems to be confined to my app, but I've run out of ideas of what to check next?
Any help is much appreciated.
Sep 26, 2019 03:25 AM|Lewis Lu|LINK
Could you share more information about your Routing configuration in Startup.cs.This problem is generally caused by the lack of configuration of the Parameter transformer.If you used a parameter transformer in a route pattern, configure it first using ConstraintMap
You could get more information in the official documentation:
There is a problem similar to yours, I hope it will help you:
Best Regards ,
Sep 26, 2019 07:41 PM|Shogun1972|LINK
Thanks for your reply, Lewis.
Well, as it turns out the startup.cs is fine as suspected. It turned out to be an error in a page directive. In my haste I had mistakenly typed
But what made it especially confusing was that the app compiled ok, and the particular page with the bug wasn't being directly called by startup.cs as far as I can tell. I discovered my error by a process of elimination. I basically created a new project
and then copied over my existing folders and pages, recompiling each time until I narrowed it down to the particular page that was causing the error.
I'd be interested if anyone can replicate the error, simply by changing the page directive in one of your pages to include my mistake above, then compile and see if you get the same error.