设置变量策略:不允许使用表达式 return 类型

Set-Variable policy: Expression return type is not allowed

Azure APIM 策略表达式可以访问 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。我希望能够将任何对象添加到字典中,但是当我尝试添加字符串以外的任何对象时,我 运行 出错了。

例如,当我尝试将其保存到我的入站策略定义中时:

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

我收到一条错误消息:

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

GroupCollection 继承自 object,因此它应该是 Variables 字典中的有效值。为什么这不起作用?

如果我尝试将其显式转换为对象:

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

我收到一条错误消息:

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

我的语法有误吗?

APIM 表达式中只允许某些类型作为变量值,对象不是其中之一,以下是目前允许作为变量值的完整列表:

  • 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[]
  • 响应
  • Jwt
  • Newtonsoft.Json.Linq.JToken