Skip to content

Fix "BadRequest" issue with WebApps InstallSiteExtensions #241

Open

Description

When adding a site extension to a web app using the following code, I receive a CloudException "Operation returned an invalid status code 'BadRequest'".

Azure
  .Configure()
  .Authenticate(credentials)
  .WithSubscription("SubscriptionId")
  .WebApps
  .Inner
  .InstallSiteExtensionAsync("ResourceGroupName", "WebAppName", "ExtensionName");

After investigation, I found that the underlying Microsoft.Azure.Management.AppService.Fluent.WebAppsOperations.BeginInstallSiteExtensionWithHttpMessagesAsync method sends no Content in its _httpRequest. Changing the auto generated code to send an empty object fixed the issue.

public async Task<AzureOperationResponse<SiteExtensionInfoInner>> BeginInstallSiteExtensionWithHttpMessagesAsync(string resourceGroupName, string name, string siteExtensionId, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
    ...

    // Serialize Request
    string _requestContent = null;

    // Added the following 3 lines
    _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(new object(), Client.SerializationSettings);
    _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
    _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");

    ...
}

I haven't looked into why the AutoRest Code Generator is creating this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions