1
votes

I have a really confusing issue, mainly because the exception I'm getting is very unhelpful and non-descriptive.

I have an ASP.Net Core-based API, and have just added a new controller. I am using ASP.Net Core 3.0, and am mapping my controllers within Startup.Configure by using the following:

app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

However, when running the API in debug I was getting the following exception on startup:

RoutePatternException: There is an incomplete parameter in the route template. Check that each '{' character has a matching '}' character.

I removed the controller and the issue disappears, so I figure there's something wrong with the controller that's causing the endpoint mapping to throw this exception but I can't see what it is?

1

1 Answers

2
votes

It was only when I reconfigured how endpoints were routed that I found the answer to the problem. I've written this out in case anybody else gets any non-descriptive exceptions from ASP.Net Core. Within Startup.Configure, I replaced:

app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

with:

app.UseMvc(routes =>
{
    routes.MapRoute("repo1", "{controller=Repo1Controller}");
    routes.MapRoute("repo2", "{controller=Repo2Controller}");
}

Then in Startup.ConfigureServices, I added:

services.AddMvc(option => option.EnableEndpointRouting = false);

Upon next startup this then showed the following exception:

RouteCreationException: The following errors occurred with attribute routing information: For action: 'MyAPI.Controllers.Repo2Controller.UpdateEntityProperty (MyAPI)'

Error: There is an incomplete parameter in the route template. Check that each '{' character has a matching '}' character. (Parameter 'routeTemplate')

In the Repo2Controller I had the following:

[HttpPut("{entityId}/Properties/{propertyId")]
public IActionResult UpdateEntityProperty(string entityId, string propertyId)
{
    // Do some stuff
}

This highlighted the fact that I was missing the closing } in the HttpPut attribute. Once I replaced this and returned to the original endpoint routing method, everything worked fine.