1
Vote

Newtonsoft.Json.JsonReaderException

description

A simple request:
{"method":"MyMethod","params":[11,46.5510462,15.61683854,36.0,"somestring"],"id":1}
Method signature:
[JsonRpcMethod]
public bool MyMethod(int a, Single? b, Single? c, Single? d, String e)
{
    // do something with a b c d e
    return true;
}
Raises an exception Newtonsoft.Json.JsonReaderException occurred with message:
Additional text encountered after finished reading JSON content: ,. Path '', line 1, position 2.

On this occassion I will slip a subquestion. Is it the correct way to implement json rpc 2.0 notification so that the method signature returns void? In above case I return dummy bool.

comments

AustinHarris wrote Oct 2, 2013 at 10:48 PM

Thanks for posting the issue, I'll see if I can reproduce it.

As for your sub question, you should be able to do notification by simply excluding the "id" parameter.
That should allow you to change your method signature to return void.

But its been a long time since I tested the notifications, so I may be remembering incorrectly.

and3rson wrote Oct 14, 2013 at 7:06 AM

Any news?

AustinHarris wrote Oct 14, 2013 at 4:09 PM

I have tried to reproduce your issues, but the method you provided is working for me. I am not getting an error.

In the JsonRpc source there is a TestServer project. I added your method to the TestServer.TestService class and then started the server and navigated to the HttpGetExamples.html page where I pasted in the Request you provided. This worked for me.

and3rson wrote Oct 15, 2013 at 4:14 PM

Could it depend on Newtonsoft version?

AustinHarris wrote Oct 16, 2013 at 7:35 PM

Its possible, that's what does the parsing.
Do you get the issue when you try to reproduce using the testserver project?
Whats your environment like? Are you using the asp.net handler, or are you hooking directly into it similar to the console example?

and3rson wrote Oct 25, 2013 at 11:16 AM

Some new insights.
Environment: 32 bit Win XP, .net 4.0, and I use asp.net handler.
I have tested this with newtosoft json 4.5.0.0 and 4.5.1.1 as found json-rpc.net project.
The problem is in the Single datatype.

Method:
[JsonRpcMethod]
public Double? Test(Single a)
{
    return a;
}
This method call produces an error:
{ "method": "Test", "params": [15.1], "id": 1 }

This method call on the other hand does not:
{ "method": "Test", "params": [15], "id": 1 }
It executes ok.

The only difference is that the parameter in the first case has a decimal part and is without decimal part in a second case.

Another observation is that parameter of type Double works as expected.

And yet another observation: If one changes the output of the method to null, then the result member is omitted from json object:
[JsonRpcMethod]
public Double? Test(Single a)
{
    return null;
}
Produces this result:
{"jsonrpc":"2.0","id":1}
No result member in resulting json.

AustinHarris wrote Oct 25, 2013 at 4:08 PM

I have an idea about where to catch the parse issue for the Single data type.

Handler.cs :: Handler.CleanUpParameter

I would likely be Sunday before I could get a fix out. There are a few other items I have put in that need testing.

If you want to build your own with a fix in Handler.CleanUpParameter that may be the quickest fix. And if you do, you should post your solution and I may use it.

As for returning Null and that no returning anything... That may take a little more digging.

raistlinthewiz wrote Jun 3, 2014 at 12:28 PM

Austin I think this was caused by again the non en-us location settings which we should have fixed in the latest 1.0.4 release (with invariant culture fix)

AustinHarris wrote Sep 3, 2014 at 7:22 AM

I wonder if the latest code is not in that nupkg... strange.