question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error listing AppService certificates using fluent api

See original GitHub issue

From @NicolaiPetri on July 11, 2017 7:46

When fetching the list of certificates for specific subscription I’ll get the following exception: “Unable to deserialize the response.” Microsoft.Rest.SerializationException

The code that fails is var certificates = azure.AppServices.AppServiceCertificates.List();

The full exception is here :

Exception: Microsoft.Rest.SerializationException: Unable to deserialize the response. ---> Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Microsoft.Azure.Management.AppService.Fluent.Models.Page'1[Microsoft.Azure.Management.AppService.Fluent.Models.CertificateInner]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
 To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
 Path '', line 1, position 1.
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
    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 Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject[T](String json, JsonSerializerSettings settings)
    at Microsoft.Azure.Management.AppService.Fluent.CertificatesOperations.<ListWithHttpMessagesAsync>d__5.MoveNext()
    --- End of inner exception stack trace ---
    at Microsoft.Azure.Management.AppService.Fluent.CertificatesOperations.<ListWithHttpMessagesAsync>d__5.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Management.AppService.Fluent.CertificatesOperationsExtensions.<ListAsync>d__1.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Management.AppService.Fluent.AppServiceCertificatesImpl.<ListInnerAsync>d__4.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Management.ResourceManager.Fluent.Core.TopLevelModifiableResources`5.List()
    at Microsoft.Azure.Management.AppService.Fluent.AppServiceCertificatesImpl.Microsoft.Azure.Management.ResourceManager.Fluent.Core.CollectionActions.ISupportsListing<Microsoft.Azure.Management.AppService.Fluent.IAppServiceCertificate>.List()
    at AzureExporter2.ResourceIdCachedService.GetResourceId(IAzure azure, String resourceId, String resourceType, String resourceName) in C:\Projects\Dashboard\azure_exporter\AzureExporter2\ResourceIdCachedService.cs:line 47
    at AzureExporter2.Program.<>c__DisplayClass1_0.<Main>b__1(IAsyncResult ar) in C:\Projects\Dashboard\azure_exporter\AzureExporter2\Program.cs:line 88

I can on request provide the failing and valid json response in a private message.

Copied from original issue: Azure/azure-sdk-for-net#3474

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
eydelriverocommented, Jul 9, 2018

Hi. Any update on this?

3reactions
Suchimancommented, Apr 17, 2019

Here’s a workaround:

class FixCertificatesHandler : DelegatingHandler
{
    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        HttpResponseMessage resp = await base.SendAsync(request, cancellationToken);
        if (resp.StatusCode == System.Net.HttpStatusCode.OK && Regex.IsMatch(request.RequestUri.LocalPath, "^/subscriptions/[^/]+/providers/Microsoft.Web/certificates$"))
        {
            var str = await resp.Content.ReadAsStringAsync();
            str = "{ \"value\": " + str + " }";
            resp.Content.Dispose();
            resp.Content = new StringContent(str);
        }
        return resp;
    }
}

and then use Azure.Configure().WithDelegatingHandler(new FixCertificatesHandler())

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error listing AppService certificates using fluent api #3474
When fetching the list of certificates for specific subscription I'll get the following exception: "Unable to deserialize the response.
Read more >
Microsoft.Azure.Management.AppService.Fluent.Models ...
Object with a list of the resources that need to be moved and the resource group they should be moved to. CsmOperationDescription. Description...
Read more >
Problems installing a TLS certificate on an Azure App ...
The trouble is that documentation and code samples for the SDK are woefully sparse. How can I upload and install a third-party TLS...
Read more >
FAQ SSL certificates for Web Apps and App Service ...
Here is a list of commonly asked questions for App Service Certificates. How do I purchase and configure a new SSL certificate in...
Read more >
application gateway · Community - Azure Feedback
Currently during my app service certificate renewal, my application gateway does not automatically update the new certificate. This caused my application ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found