Sending byte array

Aug 24, 2014 at 2:19 AM
Edited Aug 24, 2014 at 2:37 AM
I'm trying to send through json rpc a byte array.

I have built a method like this:
 [JsonRpcMethod]
        public string UploadFile(string guid, string fileName, int bytesFrom, int bytesSize, byte[] content)
        {
            return "Executed";
        }
and try to send message like this:
{"method":"UploadFile","params":["d0b487f0-e197-4666-a622-fb2339c9485e","aaa",0,64,"VABvACAAagBlAHMAdAAgAG8AZwByAG8AbQBuAHkAIAB0AGUAawBzAHQAIABvAGoAZQBqAHUAagB1AGUAagB1AA=="],"id":1}
Unfortunately server answers with an error like this:
{"jsonrpc":"2.0",
  "error":{
    "code":-32603,
    "message":"Internal Error",
    "data":{
      "ClassName":"System.ArgumentException",
      "Message":"Object type 'Newtonsoft.Json.Linq.JValue' cannot be converted to type 'System.Byte[]'.",
      "Data":null,
      "InnerException":null,
      "HelpURL":null,
      "StackTraceString":"   w System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)\r\n   w System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)\r\n   w System.Reflection.RuntimeMethodInfo.UnsafeInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n   w System.Delegate.DynamicInvokeImpl(Object[] args)\r\n   w AustinHarris.JsonRpc.Handler.Handle(JsonRequest Rpc, Object RpcContext)",
      "RemoteStackTraceString":null,
      "RemoteStackIndex":0,
      "ExceptionMethod":"8\nTryChangeType\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.RuntimeType\nSystem.Object TryChangeType(System.Object, System.Reflection.Binder, System.Globalization.CultureInfo, Boolean)",
      "HResult":-2147024809,
      "Source":"mscorlib",
      "WatsonBuckets":null,
      "ParamName":null
      }
    },
  "id":1}
Can anybody help with this. How to send byte[] to server?
Coordinator
Sep 3, 2014 at 7:28 AM
I imagine the issue is that you are passing a string to a function that wants to deserialize it into a byte[]. The easiest thing would be to change you function to take a string, then do the conversion.

You can see in the error that it doesn't think it can convert the "Newtonsoft.Json.Linq.JValue" to a "System.Byte[]'. Its possible that we could try to do that conversion for you in this situation. If you think that still makes sense, then I suggest posting an issue over at GitHub. We are trying to move over to that site. https://github.com/Astn/JSON-RPC.NET