0

I'm trying to call a web api from .Net CF 2.0 code. The api works well and called directly from the browser, behaves as expected. The CF code compiles well, but when in debug, it fails on line

JSONResponse rp = JsonConvert.DeserializeObject<JSONResponse>(returnString);

JSONResponse class is:

    public class JSONResponse{
    [JsonProperty(PropertyName = "DbServerInstance")]
    public string dbServerInstance { get; set; }

    [JsonProperty(PropertyName = "DbServerUser")]
    public string dbServerUser { get; set; }

    [JsonProperty(PropertyName = "DbServerPassword")]
    public string dbServerPassword { get; set; }

    [JsonProperty(PropertyName = "DbServerDatabase")]
    public string dbServerDatabase { get; set; }

    [JsonProperty(PropertyName = "UserManualURL")]
    public string userManualURL { get; set; }

    [JsonProperty(PropertyName = "ApplicationName")]
    public string applicationName { get; set; }
}

Error which I get is: {"Could not load type 'System.Runtime.CompilerServices.CompilerGeneratedAttribute' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC'."} System.Exception {System.TypeLoadException}

Should I upgrade the project to .Net CF 3.5? Or is it something else?

Any help and input appreciated.

edit: upgraded the project to CF 3.5, I'm getting the expected JSON string

<ArrayOfParameterSetUpdater><ParameterSetUpdater><DbServerDatabase>Py0/Pzw/MgM/Pz8/Rj8=</DbServerDatabase><DbServerInstance>PwlAaWU/cD8/fgo/Pyg/VQ==</DbServerInstance><DbServerPassword>PxUqNj9VO2Y/DV4vP0Z2Cg==</DbServerPassword><DbServerUser>FQEvDTI/QQwSP1I/Pz8/Pw==</DbServerUser><id>1</id></ParameterSetUpdater></ArrayOfParameterSetUpdater>

but now I get error {"Cannot deserialize JSON array into type 'app.JSONResponse'."} System.Exception {Newtonsoft.Json.JsonSerializationException}

From what I see, the class is correct, so I don't understand what is going wrong.

Any help and input appreciated.

user9671207
  • 33
  • 2
  • 8
  • Related or duplicate: [JSON.NET Visual Studio 2008 and .NET 3.5 Compact Framework](https://stackoverflow.com/a/49541526/3744182). That answer tells you how to use Json.NET with .Net CF 3.5. Do you need us to look into .Net CF 2.0? I *think* (but am not sure) Json.NET 3.5.8 also works with .Net CF 2.0 – dbc Sep 10 '19 at 22:15
  • Also, for the `JsonSerializationException`, can you please [edit] your question to share the full `ToString()` output of the exception including the exception type, message, traceback and inner exception(s) if any? – dbc Sep 10 '19 at 22:19

0 Answers0