Skip to content

[BUG] Virtual Hubs - Get Outbound Routes and Get Inbound Routes don't work with Relative Uri #49779

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

Closed
oakmanjacob opened this issue May 1, 2025 · 1 comment · Fixed by #50048
Assignees
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

Comments

@oakmanjacob
Copy link

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.

if (Optional.IsDefined(ResourceUri))
{
    writer.WritePropertyName("resourceUri"u8);
    writer.WriteStringValue(ResourceUri.AbsoluteUri);
}

protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)

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.

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.

Uri("/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/expressRouteGateways/exrGw1/expressRouteConnections/exrConn1", UriKind.Relative)
Error: System.InvalidOperationException: This operation is not supported for a relative URI.
   at System.Uri.get_AbsoluteUri()
   at Azure.ResourceManager.Network.Models.VirtualHubInboundRoutesContent.System.ClientModel.Primitives.IJsonModel<Azure.ResourceManager.Network.Models.VirtualHubInboundRoutesContent>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)

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.

Uri("https://management.azure.com/{{my actual connection uri}}")
Error: Azure.RequestFailedException: Resource https://management.azure.com/{{my actual connection uri}} not found
Status: 400 (Bad Request)
ErrorCode: ResourceNotFound

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

using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Network.Models;
using Azure.ResourceManager.Network;

// Generated from example definition: specification/network/resource-manager/Microsoft.Network/stable/2024-05-01/examples/GetInboundRoutes.json
// this example is just showing the usage of "VirtualHubs_GetInboundRoutes" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this VirtualHubResource created on azure
// for more information of creating VirtualHubResource, please refer to the document of VirtualHubResource
string subscriptionId = "subid";
string resourceGroupName = "rg1";
string virtualHubName = "virtualHub1";
ResourceIdentifier virtualHubResourceId = VirtualHubResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, virtualHubName);
VirtualHubResource virtualHub = client.GetVirtualHubResource(virtualHubResourceId);

// invoke the operation
VirtualHubInboundRoutesContent content = new VirtualHubInboundRoutesContent
{
    ResourceUri = new Uri("/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/expressRouteGateways/exrGw1/expressRouteConnections/exrConn1"),
    ConnectionType = "ExpressRouteConnection",
};
ArmOperation<EffectiveRouteMapRouteList> lro = await virtualHub.GetVirtualHubInboundRoutesAsync(WaitUntil.Completed, content);
EffectiveRouteMapRouteList result = lro.Value;

Console.WriteLine($"Succeeded: {result}");

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

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 1, 2025
@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 and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels May 1, 2025
@jsquire
Copy link
Member

jsquire commented May 1, 2025

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

HarveyLink added a commit to HarveyLink/azure-sdk-for-net that referenced this issue May 14, 2025
@HarveyLink HarveyLink linked a pull request May 14, 2025 that will close this issue
@ArthurMa1978 ArthurMa1978 removed the customer-reported Issues that are reported by GitHub users external to the Azure organization. label May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants