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=4.0.0.0,
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
#else
assembly = Assembly.Load(assemblyName);
#endif
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
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
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.