Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use newtonsoft JObject for CosmosDbTrigger input parameter #2891

Open
vakuras opened this issue Dec 8, 2024 · 0 comments
Open
Labels
Needs: Triage (Functions) potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug

Comments

@vakuras
Copy link
Member

vakuras commented Dec 8, 2024

Description

Hi,

I'm getting the following exception:

Error converting 1 input parameters for Function 'DeviceDedupe': Cannot convert input parameter 'documents' to type 'System.Collections.Generic.IReadOnlyList`1[[Newtonsoft.Json.Linq.JObject, Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed]]' from type 'System.String'. Error:System.Text.Json.JsonException: The JSON value could not be converted to Newtonsoft.Json.Linq.JToken. Path: $[0].metadata | LineNumber: 0 | BytePositionInLine: 14.
   at System.Text.Json.ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Type propertyType)
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonDictionaryConverter`3.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TDictionary& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObjectAsync(Stream utf8Json, CancellationToken cancellationToken)
   at Microsoft.Azure.Functions.Worker.Converters.JsonPocoConverter.GetConversionResultFromDeserialization(Byte[] bytes, Type type) in D:\a\_work\1\s\src\DotNetWorker.Core\Converters\JsonPocoConverter.cs:line 66,
Microsoft.Azure.Functions.Worker.FunctionInputConverterException,

I'm using services.AddMvc().AddNewtonsoftJson() to setup newtonsoft json.

Trigger:

public async Task Function(
    [CosmosDBTrigger(dbName, containerName,
        Connection = "CosmosDBConnection",
        LeaseContainerName = leaseContainerName,
        LeaseContainerPrefix = leaseContainerPrefix,
        MaxItemsPerInvocation = D500,
        CreateLeaseContainerIfNotExists = true)]
    IReadOnlyList<JObject> documents)
@vakuras vakuras added the potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage (Functions) potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug
Projects
None yet
Development

No branches or pull requests

1 participant