You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why do I have an error when I force the type of my parameter to Int?
If I remove the type declaration (just "[int]" in the param block) it works without any error.
Problem is : I need to distinguish a string from an int passed to my Rest API. Is that possible?
PS C:\>Invoke-RestMethod-Uri 'http://localhost:3000/api/test'-Method POST -Body {value=2}
error
-----@{message=Cannot process argument transformation on parameter 'value'. Cannot convert the "2" value of type "Microsoft.Extensions.Primitives.StringValues" t...
Error log :
18:02:11 ExecutionService Error executing endpoint script. Cannot process argument transformation on parameter 'value'. Cannot convert the "2" value of type "Microsoft.Extensions.Primitives.StringValues" to type "System.Int32".
18:02:11 ComponentController {"Error":{"message":"Cannot process argument transformation on parameter 'value'. Cannot convert the \"2\" value of type \"Microsoft.Extensions.Primitives.StringValues\" to type \"System.Int32\".","location":nul
l,"type":"error","id":null,"refreshInterval":0,"autoRefresh":false,"hasCallback":false}}
The text was updated successfully, but these errors were encountered:
If I remove the type declaration it works as expected.
As I always oblige myself to declare types when I know them, is it bad to do that in the context of a Rest API?
Here is what I get without declaring any type in the param block of my Endpoint:
PS C:\>$i=Invoke-RestMethod-Uri 'http://localhost:3000/api/test'-Method POST -Body {value=2}
PS C:\>$i.gettype()
IsPublic IsSerial Name BaseType
----------------------------
True True Int64 System.ValueType
PS C:\>$i=Invoke-RestMethod-Uri 'http://localhost:3000/api/test'-Method POST -Body {value='2'}
PS C:\>$i.gettype()
IsPublic IsSerial Name BaseType
----------------------------
True True String System.Object
Why do I have an error when I force the type of my parameter to Int?
If I remove the type declaration (just "[int]" in the param block) it works without any error.
Problem is : I need to distinguish a string from an int passed to my Rest API. Is that possible?
Here's my server code:
Client call:
Error log :
The text was updated successfully, but these errors were encountered: