Azure / azure-libraries-for-java

Azure Management Libraries for Java
https://docs.microsoft.com/en-us/java/azure/
MIT License
94 stars 98 forks source link

[BUG] genericResources.getById() throws error when used for GalleryImageVersion IDs. #1293

Closed ashbondu closed 3 years ago

ashbondu commented 3 years ago

Describe the bug genericResources.getById() throws error when used for for GalleryImageVersion IDs /subscriptions/<subscription>/resourceGroups/<resource-group>/providers/Microsoft.Compute/galleries/<image_gallery>/images/<image>/versions/1.0.0

The apiVersion generated by the SDK when making the call is not correct.

Exception or Stack Trace com.microsoft.azure.CloudException: Status code 400, {"error":{"code":"NoRegisteredProviderFound","message":"No registered resource provider found for location 'westus2' and API version '2017-10-15-preview' for type 'galleries/images/versions'. The supported api-versions are '2018-06-01, 2019-03-01, 2019-07-01, 2019-12-01, 2020-09-30'. The supported locations are 'westcentralus, southcentralus, eastus2, southeastasia, westeurope, westus, eastus, canadacentral, northeurope, northcentralus, brazilsouth, ukwest, westindia, eastasia, australiaeast, japaneast, koreasouth, westus2, canadaeast, uksouth, centralindia, southindia, australiasoutheast, japanwest, koreacentral, francecentral, centralus, australiacentral, southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast'."}} : No registered resource provider found for location 'westus2' and API version '2017-10-15-preview' for type 'galleries/images/versions'. The supported api-versions are '2018-06-01, 2019-03-01, 2019-07-01, 2019-12-01, 2020-09-30'. The supported locations are 'westcentralus, southcentralus, eastus2, southeastasia, westeurope, westus, eastus, canadacentral, northeurope, northcentralus, brazilsouth, ukwest, westindia, eastasia, australiaeast, japaneast, koreasouth, westus2, canadaeast, uksouth, centralindia, southindia, australiasoutheast, japanwest, koreacentral, francecentral, centralus, australiacentral, southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast'. at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at com.microsoft.rest.ServiceResponseBuilder.build(ServiceResponseBuilder.java:122) at com.microsoft.azure.AzureResponseBuilder.build(AzureResponseBuilder.java:56) at com.microsoft.azure.management.resources.implementation.ResourcesInner.getByIdDelegate(ResourcesInner.java:2456) at com.microsoft.azure.management.resources.implementation.ResourcesInner.access$1300(ResourcesInner.java:46) at com.microsoft.azure.management.resources.implementation.ResourcesInner$88.call(ResourcesInner.java:2443) at com.microsoft.azure.management.resources.implementation.ResourcesInner$88.call(ResourcesInner.java:2439)

weidongxu-microsoft commented 3 years ago

@ashbondu

Then please use the version provided by server, e.g. 2020-09-30, via withApiVersion. The api-version by SDK is only its best guess, and as a convenient shortcut. Sometimes the guess is wrong.