Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6214957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:58:08+00:00 2026-05-24T06:58:08+00:00

I have the following code which is part of unit testing for serialization support

  • 0

I have the following code which is part of unit testing for serialization support in my API:

    private void TestGraphSerializationJson(IGraph g)
    {
        StringWriter writer = new StringWriter();
        JsonSerializer serializer = new JsonSerializer();
        //The following line should make the serializer output type names
        //in the JSON but seems to be ignored
        serializer.TypeNameHandling = TypeNameHandling.All;

        serializer.Serialize(new JsonTextWriter(writer), g);
        Console.WriteLine("Serialized Form:");
        Console.WriteLine(writer.ToString());
        Console.WriteLine();

        Object h = serializer.Deserialize<Graph>(new JsonTextReader(new StringReader(writer.ToString())));// as Graph;
        Console.WriteLine(h.GetType().FullName);
        Assert.AreEqual(g, h, "Graphs should be equal");
    }

Various classes in my API implement the ISerializable interface and Json.Net quite happily serializes my classes into appropriate JSON.

The problem is that when I try and deserialize my object I get a fairly epic stack trace and the following error message:

Test method VDS.RDF.Test.Writing.Serialization.GraphSerializationTests.SerializationJsonGraph threw exception: Newtonsoft.Json.JsonSerializationException: ISerializable type ‘VDS.RDF.INode’ does not have a valid constructor..

Now the problem seems to be that Json.Net is trying to use ISerializable but that the particular objects I’m deserializing are typed as interfaces so it is trying to instantiate the interface rather than the actual implementations of that interface that were originally serialized.

So investigating further I saw that the Json.Net provides a TypeNameHandling setting on the serializer which can be used to include type names. So I set this to All as you can see in the code snippet but this does not seem to have any effect. The only types that gets type names inserted are List<T> types which is no help to me and still leaves me with the same frustrating error message.

Have I done something wrong here or is there a bug with Json.Net and the TypeNameHandling setting?

For the record I am using the latest Json.Net release albeit the .Net 3.5 build

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:58:08+00:00Added an answer on May 24, 2026 at 6:58 am

    This actually appears to be bug in Json.Net after further investigation.

    I have posted this along with a more minimal test case and patch that fixes the issue at http://json.codeplex.com/workitem/21215

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, which is run every 10ms as part of a
I have the following code which is the bottleneck in one part of my
I have the following code which is a part of my digital clock: library
I have the following Template Haskell code in my module, which is part of
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
I have the following code which works just fine when the method is POST,
I have the following code which works fine. However, I only want to return
I have the following code which should put programs startable in Bash. if [
I have the following code which reads in the follow file, append a \r\n

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.