BindingFailure in deserializing via JSON.Net 4.0 r3

I am trying to deserialize a JSON string that was serialized by JSON.Net 4.0 r3 itself. The settings are the same for serialization and deserialization. The following exception occurs:

Could not find type 'System.Collections.Generic.List`1[[System.Drawing.PointF, System.Drawing]]' in assembly '"mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"'

After turning on "stop when BindingFailure is thrown", I see the problem is in the following part (JSON.Net source code, DefaultSerializationBinder.cs):

  if (assemblyName != null)
    Assembly assembly;

#if !SILVERLIGHT && !PocketPC
    // look, I don't like using obsolete methods as much as you do but this is the only way
    // Assembly.Load won't check the GAC for a partial name
#pragma warning disable 618,612
    assembly = Assembly.LoadWithPartialName(assemblyName);
#pragma warning restore 618,612
    assembly = Assembly.Load(assemblyName);

    if (assembly == null)
      throw new JsonSerializationException("Could not load assembly '{0}'.".FormatWith(CultureInfo.InvariantCulture, assemblyName));

    Type type = assembly.GetType(typeName); // BindingFailure here
    if (type == null)
      throw new JsonSerializationException("Could not find type '{0}' in assembly '{1}'.".FormatWith(CultureInfo.InvariantCulture, typeName, assembly.FullName));

The error shown at the point of BindingFailure is

The assembly with display name 'System.Drawing' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'System.Drawing' or one of its dependencies. The system cannot find the file specified.

The operating system is Windows 7, 64-bit. I am using Visual Studio 2010 and targeting this application for Framework v4. The target is not Silverlight or PocketPC.

Why would it fail to load "System.Drawing" in this case? Where should I start investigating whether this is a JSON.Net issue or a problem with my Framework 4.0 installation?

Thanks in advance.


It turns out the issue is related to JSON.Net. I used to use the following setting

jsonSerializerSettings = new JsonSerializerSettings
     TypeNameHandling = TypeNameHandling.All

This was because of a suggestion in a post (that involved deserializing generic collections like List). It was suggested that full type information would help with JSon.Net errors about the "Cannot instantiate abstract base classes" error message.

If I change it to

jsonSerializerSettings = new JsonSerializerSettings
     TypeNameHandling = TypeNameHandling.Auto

it works fine. Interestingly, some type information does not get emitted, I do not get the BindingFailure and the deserialization works fine. I have no idea why it did not work with "Auto" in the first place.

Need Your Help

Need help using Read7BitEncodedInt

c# .net binary binarywriter 7bit

I've been searching for 2 hours or better for a way to use the Read7BitEncodedInt method for this. I need to use it somehow to reduce my file size (in this case likely by 100mb or more). I was also

How to sum field across two DataFrames when the indexes don't line up?

python pandas

I am brand new to complex data analysis in general, and to pandas in particular. I have a feeling that pandas should be able to handle this task easily, but my newbieness prevents me from seeing th...