0
votes

Azure APIM Policy Expressions have access to a context object that has a Variables property, which is supposed to be of type IReadOnlyDictionary<string, object>. I should be able to add values to that dictionary via the set-variable policy. I want to be able to add any object to the dictionary, but I'm running into errors when I try to add anything other than a string.

For example, when I attempt to save this into my inbound policy definition:

<set-variable name="regexGroups" value="@(Regex.Match("inputString","regex").Groups)" />

I get an error that reads:

Error in element 'set-variable' on line X, column Y: Expression return type 'System.Text.RegularExpressions.GroupCollection, System' is not allowed.

GroupCollection inherits from, object, so it should be a valid value in the Variables dictionary. Why doesn't this work?

If I try to explicitly cast it as an object:

<set-variable name="regexGroups" value="@((object)Regex.Match("inputString","regex").Groups)" />

I get an error that reads:

Error in element 'set-variable' on line X, column Y: Expression return type 'System.Object' is not allowed

Am I getting the syntax wrong?

1

1 Answers

0
votes

Only some types are allowed as variable values in APIM expressions, object is not one of them, here is the full list of what is allowed as variable value at the moment:

  • System.Boolean
  • System.SByte
  • System.Byte
  • System.UInt16
  • System.UInt32
  • System.UInt64
  • System.Int16
  • System.Int32
  • System.Int64
  • System.Decimal
  • System.Single
  • System.Double
  • System.Guid
  • System.String
  • System.Char
  • System.DateTime
  • System.TimeSpan
  • System.Byte[]
  • IResponse
  • Jwt
  • Newtonsoft.Json.Linq.JToken