C#C
C#4y ago
malkav

Azure function returning error

Here is the error I get from the Azure function test:
2022-09-21T14:04:51.850 [Error] Executed 'MergeSingleAsync' (Failed, Id=f50af7c5-6b25-4c1a-ab39-7f8aff066255, Duration=2ms)The best overloaded method match for 'string.this[int]' has some invalid arguments


Here is my Azure function (in two or three messages because of its size)
public static class MergeSingleAsync
{
    [FunctionName("MergeSingleAsync")]
    public static async Task<IActionResult> RunAsync(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
        HttpRequest req, ILogger log)
    {
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        Dictionary<string, dynamic> mainObject =
            JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(data["main_object"]);
        Dictionary<string, dynamic> secondaryObject =
            JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(data["secondary_object"]);
        dynamic matching = data["matching_property"];
        string[] mergingProperties = data["merge_properties"] == null
            ? Array.Empty<string>()
            : (string[])JsonConvert.DeserializeObject<string[]>(data.merge_properties);
        if (!mainObject.ContainsKey(matching) && !secondaryObject.ContainsKey(matching) &&
            mainObject[matching] != secondaryObject[matching])
            throw new($"The matching property: {matching} did not match in both objects provided to the function");
        return mergingProperties.Length == 0
            ? MergeAll(mainObject, secondaryObject)
            : MergeSpecific(mainObject, secondaryObject, mergingProperties);
    }
Was this page helpful?