SDK serialization when Invoking services doesn't work properly with primitive data types
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 378
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 5
Description
F# code
```
// app1
[]
member __.StopFeed(contract: string) = task {
let! resp = daprClient.InvokeMethodAsync("app2, "method1", contract)
return ()
}
```
```
// app2
[]
member __.Method1(strIn: string) = task {
return strIn
}
```
Method1 is called, but strIn is not passed (it is null even if the contract in the call is not null)
InvokeMethodAsync fails with the following exception:
```
Dapr.Client.InvocationException: An exception occurred while invoking method: 'method1' on app-id: 'app2'
---> System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Utf8JsonReader.Read()
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
```
if I change app2 as follows, so to return an actual string
```
[]
member __.Method1(strIn: string) = task {
return "Result"
}
```
a different exception is raised:
```
Dapr.Client.InvocationException: An exception occurred while invoking method: 'method1' on app-id: 'app2'
---> System.Text.Json.JsonException: 'R' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
---> System.Text.Json.JsonReaderException: 'R' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.Utf8JsonReader.Read()
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
```
I tried with int instead of string (of course changing both applications). In this case there is no exception, but Method1 receives always 0 even if the sent value is not 0.
Note that if I use a complex types, like a POCO class, instead of simple strings or ints, everything works as expected.
I encountered similar issues when invoking Actor methods and Publishing with PubSub
Contributor guide
Assessment
This issue has not been assessed yet.