Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] GetEffectiveNetworkSecurityGroups fails with Json exception due to improper type handling #34094

Closed
simonlrostron opened this issue Feb 12, 2023 · 4 comments · Fixed by #34227
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Network question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@simonlrostron
Copy link

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
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Feb 12, 2023
@jsquire jsquire added Network Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Feb 12, 2023
@jsquire
Copy link
Member

jsquire commented Feb 12, 2023

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Feb 12, 2023
@jsquire
Copy link
Member

jsquire commented Feb 12, 2023

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@ArcturusZhang
Copy link
Member

ArcturusZhang commented Feb 16, 2023

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

@ArcturusZhang ArcturusZhang added the Service Attention Workflow: This issue is responsible by Azure service team. label Feb 16, 2023
@ghost
Copy link

ghost commented Feb 16, 2023

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:

Network, Service Attention, Mgmt, customer-reported, question, needs-team-attention

Milestone: -

ArcturusZhang added a commit that referenced this issue Feb 22, 2023
* initial attempt

* mitigate the breaking change

* resolve comments

* update changelog
@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Network question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
4 participants