Repository navigation
[BUG] Azure.ResourceManager.Network - error parsing WebApplicationFirewallPolicyResource #63556
Description
Library name and version
Azure.ResourceManager.Network 1.16 and later
Describe the bug
When retrieving a WebApplicationFirewallPolicy from Application Gateway I get the following exception:
InvalidOperationException: The requested operation requires an element of type 'String', but the target element has type 'Number'.
...with the following stack trace:
at System.Text.Json.ThrowHelper.ThrowJsonElementWrongTypeException (System.Text.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
at System.Text.Json.JsonDocument.GetString (System.Text.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
at Azure.ResourceManager.Network.Models.ManagedRuleSetRuleGroup.DeserializeManagedRuleSetRuleGroup (Azure.ResourceManager.Network, Version=1.17.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at Azure.ResourceManager.Network.Models.ManagedRuleSet.DeserializeManagedRuleSet (Azure.ResourceManager.Network, Version=1.17.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at Azure.ResourceManager.Network.Models.ManagedRulesDefinition.DeserializeManagedRulesDefinition (Azure.ResourceManager.Network, Version=1.17.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at Azure.ResourceManager.Network.Models.WebApplicationFirewallPolicyPropertiesFormat.DeserializeWebApplicationFirewallPolicyPropertiesFormat (Azure.ResourceManager.Network, Version=1.17.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at Azure.ResourceManager.Network.WebApplicationFirewallPolicyData.DeserializeWebApplicationFirewallPolicyData (Azure.ResourceManager.Network, Version=1.17.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at Azure.ResourceManager.Network.WebApplicationFirewallPolicyData.FromResponse (Azure.ResourceManager.Network, Version=1.17.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at Azure.ResourceManager.Network.WebApplicationFirewallPolicyResource+<GetAsync>d__14.MoveNext (Azure.ResourceManager.Network, Version=1.17.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
The WebApplicationFirewallPolicy contains this piece:
"managedRules": {
"managedRuleSets": [
{
"ruleSetType": "OWASP",
"ruleSetVersion": "3.2",
"ruleGroupOverrides": [],
"computedDisabledRules": [
{
"ruleGroupName": "Known-CVEs",
"rules": [
800116
]
}
]
},
Note that the "rules" array contains numbers, not strings, which I believe causes the exception.
This excact bug was reported and fixed earlier in #51467.
It looks like this library was migrated from AutoRest in version 1.16, so I guess the fix was lost in the migration?
Expected behavior
The ARM response body should be returned without exception.
Actual behavior
When the computedDisabledRules has content, the parsing crashes.
See the old issue #51467 for more details (everythings looks exactly the same for me now)
Reproduction Steps
var client = new ArmClient(tokenCredential);
var wafPolicyResourceId = new ResourceIdentifier("/subscriptions/aaa/resourceGroups/bbb/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/ccc");
Response<WebApplicationFirewallPolicyResource> wafPolicy = await client.GetWebApplicationFirewallPolicyResource(wafPolicyResourceId).GetAsync();
Environment
No response
Activity
github-actions commentedon Oct 1, 2026
Thank you for your feedback. Tagging and routing to the team member(s) best able to assist.
github-actions commentedon Oct 1, 2026
🎯 Agentic Issue Triage
Summary: Deserializing a
WebApplicationFirewallPolicyResourcewhose managed rule set includescomputedDisabledRuleswith numeric rule IDs throwsInvalidOperationExceptionbecause the generated deserializer expects a JSON string but the service returns a number.📋 Issue Details
Package:
Azure.ResourceManager.Network1.16+ (reproduced on 1.17.0)Affected API:
ManagedRuleSetRuleGroup.DeserializeManagedRuleSetRuleGroup(viaWebApplicationFirewallPolicyData.FromResponse/WebApplicationFirewallPolicyResource.GetAsync)Scenarios:
GetWebApplicationFirewallPolicyResource(...).GetAsync()on a policy whosemanagedRules.managedRuleSets[].computedDisabledRules[].rulesarray contains numeric values (e.g.800116) instead of strings.Root ask: The ARM response body should deserialize without throwing; numeric rule IDs in
computedDisabledRules.rulesshould be accepted (as strings or converted) rather than causing a hard failure.🔎 Debugging / Reproduction Notes
This appears to be a regression from the generator/AutoRest-to-TypeSpec migration in v1.16. The exact same root cause was previously reported and fixed in #51467 (
NetworkExtensions.GetWebApplicationFirewallPoliciesthrowingJsonElementWrongTypeExceptionfor the samerulesproperty), suggesting the prior fix (likely a lenient string/number read, e.g. viaGetString()fallback orJsonElement.ToString()) was lost during the TypeSpec-based regeneration.Suggested investigation steps:
ManagedRuleSetRuleGroup/rulesagainst the current TypeSpec-generated code to confirm the lenient numeric-to-string handling was dropped.ManagedRuleSetRuleGroup.Rulesand adjust the type or add a customized reader that tolerates both JSON string and number tokens (mirroring the fix applied for [BUG] Azure.ResourceManager.Network.NetworkExtensions.GetWebApplicationFirewallPolicies throws JsonElementWrongTypeException #51467).computedDisabledRules[].rulesto prevent this from recurring in future regenerations.🏷️ Label Confidence
Mgmt— Issue is aboutAzure.ResourceManager.Network, a management-plane library.Network - Application Gateway— The WAF policy / managed rule sets are part of Application Gateway; this exactly matches the service label used on the prior identical-bug issue ([BUG] Azure.ResourceManager.Network.NetworkExtensions.GetWebApplicationFirewallPolicies throws JsonElementWrongTypeException #51467).customer-reported+issue-addressedpresent) confirms this exact label pairing.👥 Owner Routing
# ServiceLabel: %Mgmt(line 636) — No more specific entry forNetwork - Application Gatewayexists in CODEOWNERS, so the general%Mgmtcatch-all applies.@ArthurMa1978@ArthurMa1978; addedneeds-team-attentionsince the reporter is an external customer.%Mgmtcatch-all.github-actions commentedon Oct 1, 2026
🔍 Agentic Issue Investigation
Outcome
Recommended for Copilot automated fix
Summary
ManagedRuleSetRuleGroup.DeserializeManagedRuleSetRuleGroupcallsitem.GetString()on each element of therulesarray, which throwsInvalidOperationExceptionwhen the service returns numeric rule IDs (as it does forcomputedDisabledRules). This is the same bug previously fixed in #51467 / PR #51573, but the fix appears to have been lost when the library migrated from AutoRest to TypeSpec generation.🩹 Mitigation
No SDK-level workaround is available, since the exception occurs during deserialization of the GET response before the model is returned to caller code. As a temporary mitigation, customers can call the raw REST pipeline directly (bypassing the strongly-typed
WebApplicationFirewallPolicyResource.GetAsync) and parse the JSON manually withSystem.Text.Json, converting numericrulesentries to strings before further processing.🧭 Root Cause
In
sdk/network/Azure.ResourceManager.Network/src/Generated/Models/ManagedRuleSetRuleGroup.Serialization.cs,DeserializeManagedRuleSetRuleGroupreads therulesarray viaarray.Add(item.GetString()), which throws when the underlying JSON token is aNumberrather than aString. The reporter's response body showscomputedDisabledRules[].rulescontaining numeric values (e.g.800116), confirming this path is hit. This matches the exact pattern fixed previously in PR #51573 for the same model, but since this file is now fully generated code (migrated to TypeSpec per CHANGELOG 1.16.0), that customization was not carried forward. The current generated code (verified in the latest source onmain, versions through 1.18.0-beta.2/1.17.0 stable) still has the unguardedGetString()call, so this is confirmed present in current code.🛠️ Suggested Fix
Because this file is fully generated, the fix must be applied via a customization (partial class override of
DeserializeManagedRuleSetRuleGroup, following the pattern used for PR #51573) rather than editing the generated file directly, so it survives regeneration. The deserialization should accept bothJsonValueKind.StringandJsonValueKind.Numberfor eachrulesarray element, converting numbers to their string representation (e.g. viaitem.ToString()orGetRawText()), consistent with the original 2025 fix. A regression test should exercise a WAF policy response containing numeric values inmanagedRuleSets[].computedDisabledRules[].rulesand verify deserialization succeeds without exception.✅ Decision Basis
mainbranch generated code (latest stable 1.17.0 / prerelease 1.18.0-beta.2), so no "reproduce on latest" step is needed.A maintainer can assign Copilot to proceed. Automated assignment is best effort on this repository and may not complete.