joym8
joym8

Reputation: 4232

System.ArgumentException: In a route parameter, '{' and '}' must be escaped with '{{' and '}}'. (Parameter 'routeTemplate')

I'm porting an old API project to .NET Core 3.1 API project. All endpoints in old are working fine. While testing the new API on local IIS 10/Windows 10 I'm getting this error:

System.ArgumentException: In a route parameter, '{' and '}' must be escaped with '{{' and '}}'. (Parameter 'routeTemplate')

The specific route in question is not shown in the error. So I am including all routes here.

  1. [Route("department/{id:int}")]
  2. [Route("program/{deptId:int}")]
  3. [Route(@"employee/{samId:regex(^[[A-Za-z0-9._-]]{3,30}$)}")]
  4. [Route(@"homepage/{samId:regex(^[[a-zA-Z0-9_.-]]{3,30}$)}")]

On #2 and #3 I have double [ and double ] because I was getting error on those as well earlier when they were single.

Upvotes: 3

Views: 3060

Answers (1)

Tupac
Tupac

Reputation: 2932

According to the error message

System.ArgumentException: In a route parameter, '{' and '}' must be escaped with '{{' and '}}'. (Parameter 'routeTemplate')

you need to add one more {} in front, like this:

 [Route(@"test/{{samId:regex(^[[A-Za-z0-9._-]]{3,30}$)}}")]

Upvotes: 1

Related Questions