Azure / azure-libraries-for-net

Azure libraries for .Net
MIT License
377 stars 190 forks source link

[BUG] Exception when calling `KeyVaultManagementClient.Vaults.CheckNameAvailabilityAsync` #1311

Open jag43 opened 2 years ago

jag43 commented 2 years ago

Describe the bug Exception when calling KeyVaultManagementClient.Vaults.CheckNameAvailabilityAsync

Exception or Stack Trace Message: Unable to deserialize the response. StackTrace:

   at Microsoft.Azure.Management.KeyVault.VaultsOperations.<CheckNameAvailabilityWithHttpMessagesAsync>d__16.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Azure.Management.KeyVault.VaultsOperationsExtensions.<CheckNameAvailabilityAsync>d__23.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

Inner1 Message: Error converting value "Invalid" to type 'System.Nullable`1[Microsoft.Azure.Management.KeyVault.Models.Reason]'. Path 'reason', line 1, position 41. Inner 1 StackTrace:

   at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject[T](String json, JsonSerializerSettings settings)
   at Microsoft.Azure.Management.KeyVault.VaultsOperations.<CheckNameAvailabilityWithHttpMessagesAsync>d__16.MoveNext()

Inner2 Message: Requested value 'Invalid' was not found. Inner2 StackTrace:

   at Newtonsoft.Json.Utilities.EnumUtils.ParseEnum(Type enumType, NamingStrategy namingStrategy, String value, Boolean disallowNumber)
   at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)

To Reproduce Call KeyVaultManagementClient.Vaults.CheckNameAvailabilityAsync with an invalid name (in our case the name was too long)

Code Snippet var checkNameAvailabilityResponse = await keyVaultClient.Vaults.CheckNameAvailabilityAsync(new VaultCheckNameAvailabilityParameters(keyVaultName), cancellationToken);

Expected behavior No exception to be thrown, response is able to deserialized and we get invalid name in the response

Screenshots If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

Additional context None

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

jag43 commented 2 years ago

It seems that the azure management api returns Invalid but the only enum values are AccountNameInvalid and AlreadyExists (link)

weidongxu-microsoft commented 2 years ago

The lib is in maintenance (and to be deprecated).

Please plan migrate to https://aka.ms/azsdk/dotnet/mgmt