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?