Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

InvalidCastException when using Newtonsoft.Json.dll (10.0.1 .NET 4.0) #1050

@Kyoril

Description

@Kyoril

I get an uncaught exception of type System.InvalidCastException when I try to execute the following:

            // Load the document
            using (Stream strm = archive.GetFileStream("package.json"))
            {
                using (StreamReader reader = new StreamReader(strm))
                {
                    // The following line crashes!
                    dynamic rootObject = JsonConvert.DeserializeObject(reader.ReadToEnd());
                }
             }

The generated JSIL line that causes the crash somewhere in the NewtonSoft.Json.dll js code looks like this:

var rootObject = $T0D().DeserializeObject(($S05().Construct(strm)).ReadToEnd());

Exception message in log div:

Unhandled exception at http://127.0.0.1/web/Libraries/JSIL.Core.js line 5034:
Uncaught System.InvalidCastException: Unable to cast object of type 'Newtonsoft.Json.JsonTextReader' to type 'Newtonsoft.Json.Serialization.TraceJsonReader'.

Edit: The C# code runs just fine in a compiled Windows application, so the JSON data isn't corrupted.
Edit 2: I also checked in the javascript debugger that the stream contains the correct json text value, so everything got loaded correctly from the local file storage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions