+2010-02-26 Robert Jordan <robertj@gmx.net>
+
+ * ObjectReader.cs (ReadType, GetDeserializationType):
+ Add throwOnError parameter that specifies whether to throw an
+ exception if the type/assembly is not found.
+
+ * ObjectReader.cs (ReadTypeMetadata): Ignore unresolvable
+ types while reading the type info. Fixes #430583.
+
+ * ObjectReader.cs (GetDeserializationType): Rethrow caught
+ exceptions as SerializationExceptions.
+
2009-10-31 Sebastien Pouliot <sebastien@ximian.com>
* BinaryCommon.cs: Disable MONO_REFLECTION_SERIALIZER override
for (int n=0; n<fieldCount; n++)
codes [n] = (TypeTag) reader.ReadByte ();
- for (int n=0; n<fieldCount; n++)
- types [n] = ReadType (reader, codes[n]);
+ for (int n=0; n<fieldCount; n++) {
+ Type t = ReadType (reader, codes[n], false);
+ // The field's type could not be resolved: assume it is an object.
+ if (t == null)
+ t = typeof (object);
+ types [n] = t;
+ }
}
// Gets the type
}
private Type GetDeserializationType (long assemblyId, string className)
+ {
+ return GetDeserializationType (assemblyId, className, true);
+ }
+
+ private Type GetDeserializationType (long assemblyId, string className, bool throwOnError)
{
Type t;
string assemblyName = (string)_registeredAssemblies[assemblyId];
if (t != null)
return t;
}
-
- Assembly assembly = Assembly.Load (assemblyName);
- t = assembly.GetType (className, true);
+
+ Assembly assembly;
+ try {
+ assembly = Assembly.Load (assemblyName);
+ } catch (Exception ex) {
+ if (!throwOnError)
+ return null;
+ throw new SerializationException (String.Format ("Couldn't find assembly '{0}'", assemblyName), ex);
+ }
+
+ t = assembly.GetType (className);
if (t != null)
return t;
- throw new SerializationException ("Couldn't find type '" + className + "'.");
+
+ if (!throwOnError)
+ return null;
+
+ throw new SerializationException (String.Format ("Couldn't find type '{0}' in assembly '{1}'", className, assemblyName));
}
public Type ReadType (BinaryReader reader, TypeTag code)
+ {
+ return ReadType (reader, code, true);
+ }
+
+ public Type ReadType (BinaryReader reader, TypeTag code, bool throwOnError)
{
switch (code)
{
{
string name = reader.ReadString ();
long asmid = (long) reader.ReadUInt32();
- return GetDeserializationType (asmid, name);
+ return GetDeserializationType (asmid, name, throwOnError);
}
case TypeTag.ArrayOfObject: