Skip to content

Strongly-typed requests with named arguments produce empty params object with SystemTextJsonFormatter #1194

@posahok

Description

@posahok

net9.0, StreamJsonRpc 2.22.11

Interface declaration

public interface TestInterface
{
    public Task<int> add(int a, int b);
}

Strongly-typed request with named arguments with JsonMessageFormatter

Pipe pipe = new();

var formatter = new JsonMessageFormatter();
var handler = new LengthHeaderMessageHandler(pipe.Writer, pipe.Reader, formatter);
var jsonRpc = new JsonRpc(handler);

jsonRpc.TraceSource.Listeners.Add(new ConsoleTraceListener());
jsonRpc.TraceSource.Switch.Level = SourceLevels.Verbose;

jsonRpc.StartListening();

JsonRpcProxyOptions JsonRpcProxyOptions = new()
{
    ServerRequiresNamedArguments = true
};

TestInterface testInterface = jsonRpc.Attach<TestInterface>(JsonRpcProxyOptions);
await testInterface.add(123, 456);

Partial console output

JsonRpc Verbose: 8 : Sent: {
  "jsonrpc": "2.0",
  "id": 2,
  "method": "add",
  "params": {
    "a": 123,
    "b": 456
  }
}

Strongly-typed request with named arguments with SystemTextJsonFormatter

Pipe pipe = new();

var formatter = new SystemTextJsonFormatter();
var handler = new LengthHeaderMessageHandler(pipe.Writer, pipe.Reader, formatter);
var jsonRpc = new JsonRpc(handler);

jsonRpc.TraceSource.Listeners.Add(new ConsoleTraceListener());
jsonRpc.TraceSource.Switch.Level = SourceLevels.Verbose;

jsonRpc.StartListening();

JsonRpcProxyOptions JsonRpcProxyOptions = new()
{
    ServerRequiresNamedArguments = true
};

TestInterface testInterface = jsonRpc.Attach<TestInterface>(JsonRpcProxyOptions);
await testInterface.add(123, 456);

Partial console output

JsonRpc Verbose: 8 : Sent: {"jsonrpc":"2.0","id":2,"method":"add","params":{}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions