Json.Net causing debugging issues

SikkuDevelopersSikkuDevelopers USMember
edited November 2014 in Cross Platform with Xamarin

I am having alot of issues with remote debugging iOS from Visual Studio when I make calls to Json.net. To be clear, the operations themselves work just fine, but they cause the debugger to disconnect at application startup which is making for a real headache. Here is a code snippet example:

This works fine , but causes the debugger to end the session when the app launches:

    var resp = response.Result.Content.ReadAsStringAsync().Result;
            var x = JsonConvert.DeserializeObject(resp);

Same with something more explicit:

    var resp = response.Result.Content.ReadAsStringAsync().Result;
           Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(resp);

Removing the call to JsonConvert , means that the debugger does not crash:

    var resp = response.Result.Content.ReadAsStringAsync().Result;
           // var x = JsonConvert.DeserializeObject(resp);

The exception thrown is:

Debugger lost connection to the running application. Likely this means the application terminated unexpectedly.

Mono.Debugger.Soft.VMDisconnectedException: Exception of type 'Mono.Debugger.Soft.VMDisconnectedException' was thrown.
at Mono.Debugger.Soft.Connection.SendReceive(CommandSet command_set, Int32 command, PacketWriter packet)
at Mono.Debugger.Soft.Connection.Assembly_GetName(Int64 id)
at Mono.Debugger.Soft.AssemblyMirror.GetName()
at Mono.Debugging.Soft.SoftDebuggerSession.UpdateAssemblyFilters(AssemblyMirror asm)
at Mono.Debugging.Soft.SoftDebuggerSession.HandleAssemblyLoadEvents(AssemblyLoadEvent[] events)
at Mono.Debugging.Soft.SoftDebuggerSession.HandleEventSet(EventSet es)
at Mono.Debugging.Soft.SoftDebuggerSession.EventHandler()

Which this seems to be telling me there is something about the assembly that mono does not like , but not sure at all how to go about remedying this.

I have Newtonsoft.Json 6.0 installed via Nuget and referenced by both projects. The fact that the code works correctly seems to indicate that the correct libraries are there.

Anyone having a similar issue and figure out how to get around it?

Thanks

James

Posts

  • KMullinsKMullins USXamarin Team Xamurai

    Hi @SikkuDevelopers‌,

    Of late I've been using SimpleJson as a replacement for the Newtonsoft.Json because: a) I can embed it directly in my project without need for a 3rd party library, b) I can debug trace into it.

    It has the same calling structure as the Newtonsoft parser so I could use it without code change otherwise. I do however make one change to SimpleJson, it initially is case sensitive and I turn that off to totally match Newtonsoft.Json's functionality.

    Here is the bit I modify:

    /// <summary>
        /// Initializes a new instance of <see cref="JsonObject"/>.
        /// </summary>
        public JsonObject()
        {
            // KKM 08/01/2014 - Forced dictionary to be case insensitive
            // _members = new Dictionary<string, object>();
            _members = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        }
    

    You can install SimpleJson from NuGet. You could always use it to see what the issue is and then switch back to Newtonsoft.Json if you like.

    Hope this helps,

    Kevin

Sign In or Register to comment.