0

I'm creating a very simple Azure Function with NET8.

public async Task Run(
    [ServiceBusTrigger("wordvoice", Connection = "SBConnectionString")] 
    string message)
{
    AudioServiceBusRequest request = 
        JsonSerializer.Deserialize<AudioServiceBusRequest>(message);

    await ProcessService.ProcessAudio(request, processName, _logger);
}

In the service bus, I add a simple json like that

{
    "wordId": 33,
    "language": 1,
    "word": "go"
}

enter image description here

I created a model to receive this json

public class AudioServiceBusRequest
{
    [JsonPropertyName("wordId")]
    public long? WordId { get; set; }
    [JsonPropertyName("language")]
    public string Language { get; set; }
    [JsonPropertyName("word")]
    public string Word { get; set; }
}

When the message is received by the Azure Function, I get at least 90 lines of errors starting with

Exception: System.AggregateException: One or more errors occurred. (The JSON value could not be converted to System.String. Path: $.language | LineNumber: 2 | BytePositionInLine: 17.)

---> System.Text.Json.JsonException: The JSON value could not be converted to System.String. Path: $.language | LineNumber: 2 | BytePositionInLine: 17.

---> System.InvalidOperationException: Cannot get the value of a token type 'Number' as a string.

enter image description here

I'm using the same json in an Azure Function built with NET6 and it is working.

1 Answer 1

2

You're defining language and wordId as string...

[JsonPropertyName("language")]
public string Language { get; set; }
[JsonPropertyName("wordId")]
public string WordId { get; set; }

Change them to be int instead, to match your data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.