Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.57k stars 4.82k forks source link

[QUERY] Use arm deploy with armtemplate parameters is exception. #47326

Open FisherMS opened 1 week ago

FisherMS commented 1 week ago

Library name and version

Azure.ResourceManager.Resources 1.9.0

Query/Question

here is the parameter json file.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    }
}

C# code point:

 var txtTemplate = await File.ReadAllTextAsync(templateFile);
var properties = new ArmDeploymentProperties(ArmDeploymentMode.Incremental)
{
    Template = BinaryData.FromString(txtTemplate)
    Parameters = BinaryData.FromString(txtParameter);
};

exception:

Azure.RequestFailedException: The request content was invalid and could not be deserialized: 'Error converting value "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.$schema', line 1, position 2412.'.
Status: 400 (Bad Request)
ErrorCode: InvalidRequestContent

Content:
{"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Error converting value \"https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#\" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.$schema', line 1, position 2412.'."}}

Headers:
Cache-Control: no-cache
Pragma: no-cache
x-ms-failure-cause: REDACTED
x-ms-ratelimit-remaining-subscription-writes: REDACTED
x-ms-ratelimit-remaining-subscription-global-writes: REDACTED
x-ms-request-id: 2e6812d4-a331-42c4-8522-0d99f2d86055
x-ms-correlation-request-id: REDACTED
x-ms-routing-request-id: REDACTED
Strict-Transport-Security: REDACTED
X-Content-Type-Options: REDACTED
X-Cache: REDACTED
X-MSEdge-Ref: REDACTED
Date: Tue, 26 Nov 2024 02:51:12 GMT
Content-Length: 366
Content-Type: application/json; charset=utf-8
Expires: -1

   at Azure.Core.OperationInternal`1.GetResponseFromState(OperationState`1 state)
   at Azure.Core.OperationInternal`1.UpdateStatusAsync(Boolean async, CancellationToken cancellationToken)
   at Azure.Core.OperationInternalBase.UpdateStatusAsync(CancellationToken cancellationToken)
   at Azure.Core.OperationPoller.WaitForCompletionAsync(Boolean async, OperationInternalBase operation, Nullable`1 delayHint, CancellationToken cancellationToken)
   at Azure.Core.OperationInternalBase.WaitForCompletionResponseAsync(Boolean async, Nullable`1 pollingInterval, String scopeName, CancellationToken cancellationToken)
   at Azure.Core.OperationInternal`1.WaitForCompletionAsync(Boolean async, Nullable`1 pollingInterval, CancellationToken cancellationToken)
   at Azure.Core.OperationInternal`1.WaitForCompletionAsync(CancellationToken cancellationToken)
   at Azure.ResourceManager.Resources.ArmDeploymentResource.ValidateAsync(WaitUntil waitUntil, ArmDeploymentContent content, CancellationToken cancellationToken)
   at Aicro.AzureDeploy.Services.DefaultArmTemplateDeployProvider.ValidDeployArmTemplateAsync

Environment

dotnet8 VS2022

jsquire commented 1 week ago

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

FisherMS commented 5 days ago

I currently use the method of reading the parameter file content first, then deserializing it into an object, and then converting it into a NameValue pair of JsonObject to complete the parameter reading. Then call BinaryData.FromObjectAsJson(pmJsonObj) ok.

This is a workaround.