[BUG] Virtual Hubs - Get Outbound Routes and Get Inbound Routes don't work with Relative Uri #49779
Labels
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
Library name and version
Azure.ResourceManager.Network 1.10.0
Describe the bug
Virtual Hubs - Get Outbound Routes and Get Inbound Routes don't work in Azure.ResourceManager.Network SDK because the ResourceUri property requires an Absolute Uri while the REST API itself requires a relative uri.
The given sample will throw an exception because Uri will not be able to infer a relative uri and if you manually make it a relative uri, the Json serialization of the VirtualHubOutboundRoutesContent / VirtualHubInboundRoutesContent will fail.
https://learn.microsoft.com/en-us/rest/api/virtualwan/virtual-hubs/get-inbound-routes?view=rest-virtualwan-2024-05-01&tabs=dotnet
https://learn.microsoft.com/en-us/rest/api/virtualwan/virtual-hubs/get-outbound-routes?view=rest-virtualwan-2024-05-01&tabs=dotnet
Fix Option 1
Issue root cause seems to be coming from the Json Serialization using AbsoluteUri instead of Uri ToString.
azure-sdk-for-net/sdk/network/Azure.ResourceManager.Network/src/Generated/Models/VirtualHubInboundRoutesContent.Serialization.cs
Line 29 in 6d25121
https://github.com/Azure/azure-sdk-for-net/blob/6d25121451b912e8146020fb967393d48bb922a0/sdk/network/Azure.ResourceManager.Network/src/Generated/Models/VirtualHubOutboundRoutesContent.Serialization.cs#L31C13-L62C10
Fix Option 2
An alternate solution to this would be to update the type from Uri to be of type Azure.Core.ResourceIdentifier or even just a string like is done in the other language examples.
azure-sdk-for-net/sdk/network/Azure.ResourceManager.Network/src/Generated/Models/VirtualHubInboundRoutesContent.cs
Line 65 in b803383
azure-sdk-for-net/sdk/network/Azure.ResourceManager.Network/src/Generated/Models/VirtualHubOutboundRoutesContent.cs
Line 65 in b803383
Expected behavior
RelativeUri in VirtualHubInboundRoutesContent and VirtualHubOutboundRoutesContent should accept and send requests with a relative uri such as "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/expressRouteGateways/exrGw1/expressRouteConnections/exrConn1".
Actual behavior
Starting from example here: https://learn.microsoft.com/en-us/rest/api/virtualwan/virtual-hubs/get-inbound-routes?view=rest-virtualwan-2024-05-01&tabs=dotnet
Uri("/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/expressRouteGateways/exrGw1/expressRouteConnections/exrConn1")
Error: System.UriFormatException: 'Invalid URI: The format of the URI could not be determined.'
If we specify that this is a relative Uri, the object will successfully create but then will fail in Json Serialization for the REST call.
If we create the Uri using an absolute path, Json serialization works but the actual request will fail because the rest api is looking for a relative path.
I have verified using Azure PowerShell that the REST API does return correctly if ResourceUri is a relative uri instead of the absolute.
Reproduction Steps
Environment
.NET SDK (reflecting any global.json):
Version: 6.0.427
Commit: 93fddcf4f6
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win10-x64
Visual Studio 2022 - 17.13.6
The text was updated successfully, but these errors were encountered: