azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[BUG] GetEffectiveNetworkSecurityGroups fails with Json exception due to improper type handling
Library name and version
Azure.ResourceManager.Network 1.1.0
Describe the bug
The GetEffectiveNetworkSecurityGroups() / GetEffectiveNetworkSecurityGroupsAsync() methods in the NetworkInterfaceResource class fail when attempting to process the tagMap property in the result data.
The following exception is thrown: System.Text.Json.Rethrowable: The requested operation requires an element of type 'String', but the target element has type 'Object'.
Indeed, the property is an object in the actual API response:
"tagMap": {
"VirtualNetwork": [
"10.1.10.0/24",
"10.2.0.0/15",
"168.63.129.16/32"
],
"AzureLoadBalancer": [
"168.63.129.16/32",
"fe80::1234:5678:9abc/128"
],
"Internet": [
"1.0.0.0/8",
"2.0.0.0/7",
"4.0.0.0/9",
"4.144.0.0/12",
...
]
}
...but it seems that the code is expecting a string value.
In looking at the Swagger definitions for various versions of the /networkInterfaces API, the tagMap property definition seems to be incorrect:
"tagMap": {
"type": "string",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of IP Addresses within the tag (key)."
},
"description": "Mapping of tags to list of IP Addresses included within the tag."
}
The current public documentation for the API is accurate.
Expected behavior
Calls to these methods succeed, and the appropriate data is returned.
Actual behavior
Both the synchronous and asynchronous methods fail when the results from the operation are processed.
The following is a stacktrace:
The requested operation requires an element of type 'String', but the target element has type 'Object'.
at System.Text.Json.JsonDocument.GetString(Int32 index, JsonTokenType expectedType)
at System.Text.Json.JsonElement.GetString()
at Azure.ResourceManager.Network.Models.EffectiveNetworkSecurityGroup.DeserializeEffectiveNetworkSecurityGroup(JsonElement element) in /_/sdk/network/Azure.ResourceManager.Network/src/Generated/Models/EffectiveNetworkSecurityGroup.Serialization.cs:line 62
at Azure.ResourceManager.Network.Models.EffectiveNetworkSecurityGroupListResult.DeserializeEffectiveNetworkSecurityGroupListResult(JsonElement element) in /_/sdk/network/Azure.ResourceManager.Network/src/Generated/Models/EffectiveNetworkSecurityGroupListResult.Serialization.cs:line 32
at Azure.ResourceManager.Network.EffectiveNetworkSecurityGroupListResultOperationSource.<Azure-Core-IOperationSource<Azure-ResourceManager-Network-Models-EffectiveNetworkSecurityGroupListResult>-CreateResultAsync>d__1.MoveNext() in /_/sdk/network/Azure.ResourceManager.Network/src/Generated/LongRunningOperation/EffectiveNetworkSecurityGroupListResultOperationSource.cs:line 28
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.NextLinkOperationImplementation.OperationToOperationOfT`1.<UpdateStateAsync>d__3.MoveNext() in /_1/microsoft.azure.autorest.csharp/3.0.0-beta.20221030.1/content/Generator.Shared/NextLinkOperationImplementation.cs:line 425
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternal`1.<UpdateStatusAsync>d__20.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs:line 260
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternalBase.<UpdateStatusAsync>d__13.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs:line 87
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationPoller.<WaitForCompletionAsync>d__11.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationPoller.cs:line 79
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternalBase.<WaitForCompletionResponseAsync>d__19.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs:line 202
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternal`1.<WaitForCompletionAsync>d__19.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs:line 242
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternal`1.<WaitForCompletionAsync>d__15.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs:line 177
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.ResourceManager.Network.NetworkInterfaceResource.<GetEffectiveNetworkSecurityGroupsAsync>d__30.MoveNext() in /_/sdk/network/Azure.ResourceManager.Network/src/Generated/NetworkInterfaceResource.cs:line 393
Reproduction Steps
string nicId = "/subscriptions/.../example-nic";
NetworkInterfaceResource nicResource = this._armClient.GetNetworkInterfaceResource(ResourceIdentifier.Parse(nicId));
ArmOperation<EffectiveNetworkSecurityGroupListResult> operation = await nicResource.GetEffectiveNetworkSecurityGroupsAsync(WaitUntil.Completed);
Environment
- Azure.ResourceManager.Network 1.1.0
- .NET 6.0, Azure Functions v4
- Visual Studio 17.4.3
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Thank you for your feedback. Tagging and routing to the team member best able to assist.
HI @simonlrostron thank you for the issue! The root cause is indeed something wrong in the spec definition: https://github.com/Azure/azure-rest-api-specs/blob/7384176da46425e7899708f263e0598b851358c2/specification/network/resource-manager/Microsoft.Network/stable/2021-02-01/networkInterface.json#L1316
We defined the additionalProperties therefore the initial intent should be trying to define this as a dictionary, but we accidentally put a type: string on this property which nullifies the additionalProperties therefore in the generated code, this property is generated as a string.
Based on the actual response payload in your description, the correct type for this property should be IDictionary<string, IList<string>> and this is the type the swagger schema is trying to describe.
We will investigate this further and have an update for this very soon
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aznetsuppgithub.
Issue Details
Library name and version
Azure.ResourceManager.Network 1.1.0
Describe the bug
The GetEffectiveNetworkSecurityGroups() / GetEffectiveNetworkSecurityGroupsAsync() methods in the NetworkInterfaceResource class fail when attempting to process the tagMap property in the result data.
The following exception is thrown: System.Text.Json.Rethrowable: The requested operation requires an element of type 'String', but the target element has type 'Object'.
Indeed, the property is an object in the actual API response:
"tagMap": {
"VirtualNetwork": [
"10.1.10.0/24",
"10.2.0.0/15",
"168.63.129.16/32"
],
"AzureLoadBalancer": [
"168.63.129.16/32",
"fe80::1234:5678:9abc/128"
],
"Internet": [
"1.0.0.0/8",
"2.0.0.0/7",
"4.0.0.0/9",
"4.144.0.0/12",
...
]
}
...but it seems that the code is expecting a string value.
In looking at the Swagger definitions for various versions of the /networkInterfaces API, the tagMap property definition seems to be incorrect:
"tagMap": {
"type": "string",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of IP Addresses within the tag (key)."
},
"description": "Mapping of tags to list of IP Addresses included within the tag."
}
The current public documentation for the API is accurate.
Expected behavior
Calls to these methods succeed, and the appropriate data is returned.
Actual behavior
Both the synchronous and asynchronous methods fail when the results from the operation are processed.
The following is a stacktrace:
The requested operation requires an element of type 'String', but the target element has type 'Object'.
at System.Text.Json.JsonDocument.GetString(Int32 index, JsonTokenType expectedType)
at System.Text.Json.JsonElement.GetString()
at Azure.ResourceManager.Network.Models.EffectiveNetworkSecurityGroup.DeserializeEffectiveNetworkSecurityGroup(JsonElement element) in /_/sdk/network/Azure.ResourceManager.Network/src/Generated/Models/EffectiveNetworkSecurityGroup.Serialization.cs:line 62
at Azure.ResourceManager.Network.Models.EffectiveNetworkSecurityGroupListResult.DeserializeEffectiveNetworkSecurityGroupListResult(JsonElement element) in /_/sdk/network/Azure.ResourceManager.Network/src/Generated/Models/EffectiveNetworkSecurityGroupListResult.Serialization.cs:line 32
at Azure.ResourceManager.Network.EffectiveNetworkSecurityGroupListResultOperationSource.<Azure-Core-IOperationSource<Azure-ResourceManager-Network-Models-EffectiveNetworkSecurityGroupListResult>-CreateResultAsync>d__1.MoveNext() in /_/sdk/network/Azure.ResourceManager.Network/src/Generated/LongRunningOperation/EffectiveNetworkSecurityGroupListResultOperationSource.cs:line 28
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.NextLinkOperationImplementation.OperationToOperationOfT`1.<UpdateStateAsync>d__3.MoveNext() in /_1/microsoft.azure.autorest.csharp/3.0.0-beta.20221030.1/content/Generator.Shared/NextLinkOperationImplementation.cs:line 425
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternal`1.<UpdateStatusAsync>d__20.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs:line 260
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternalBase.<UpdateStatusAsync>d__13.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs:line 87
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationPoller.<WaitForCompletionAsync>d__11.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationPoller.cs:line 79
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternalBase.<WaitForCompletionResponseAsync>d__19.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs:line 202
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternal`1.<WaitForCompletionAsync>d__19.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs:line 242
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.OperationInternal`1.<WaitForCompletionAsync>d__15.MoveNext() in /_/sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs:line 177
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.ResourceManager.Network.NetworkInterfaceResource.<GetEffectiveNetworkSecurityGroupsAsync>d__30.MoveNext() in /_/sdk/network/Azure.ResourceManager.Network/src/Generated/NetworkInterfaceResource.cs:line 393
Reproduction Steps
string nicId = "/subscriptions/.../example-nic";
NetworkInterfaceResource nicResource = this._armClient.GetNetworkInterfaceResource(ResourceIdentifier.Parse(nicId));
ArmOperation<EffectiveNetworkSecurityGroupListResult> operation = await nicResource.GetEffectiveNetworkSecurityGroupsAsync(WaitUntil.Completed);
Environment
- Azure.ResourceManager.Network 1.1.0
- .NET 6.0, Azure Functions v4
- Visual Studio 17.4.3
| Author: | simonlrostron |
|---|---|
| Assignees: | xboxeer |
| Labels: |
|
| Milestone: | - |