private static void CheckCompatibility(TypeName typeName, Type type) { try { TypeName loadedTypeName = TypeNameParser.Parse(type.AssemblyQualifiedName); if (!typeName.IsCompatible(loadedTypeName)) { throw new PersistenceException(String.Format( "Serialized type is incompatible with available type: serialized: {0}, loaded: {1}", typeName.ToString(true, true), type.AssemblyQualifiedName)); } if (typeName.IsNewerThan(loadedTypeName)) { throw new PersistenceException(String.Format( "Serialized type is newer than available type: serialized: {0}, loaded: {1}", typeName.ToString(true, true), type.AssemblyQualifiedName)); } } catch (PersistenceException) { throw; } catch (Exception e) { Logger.Warn(String.Format( "Could not perform version check requested type was {0} while loaded type is {1}:", typeName.ToString(true, true), type.AssemblyQualifiedName), e); } }
private static Type LoadWithPartialName(TypeName typeName) { try { #pragma warning disable 0618 Assembly a = Assembly.LoadWithPartialName(typeName.AssemblyName); // the suggested Assembly.Load() method fails to load assemblies outside the GAC #pragma warning restore 0618 return(a.GetType(typeName.ToString(false, false), true)); } catch (Exception) { throw new PersistenceException(String.Format( "Could not load type \"{0}\"", typeName.ToString(true, true))); } }
private static Type LoadInternal(TypeName typeName) { Type type; try { type = Type.GetType(typeName.ToString(true, true), true); } catch (Exception) { Logger.Warn(String.Format( "Cannot load type \"{0}\", falling back to partial name", typeName.ToString(true, true))); type = LoadWithPartialName(typeName); CheckCompatibility(typeName, type); } return(type); }
private static Type LoadInternal(TypeName typeName) { Type type; try { type = Type.GetType(typeName.ToString(true, true), true); } catch (Exception) { Logger.Warn(String.Format( "Cannot load type \"{0}\", falling back to partial name", typeName.ToString(true, true))); type = LoadWithPartialName(typeName); CheckCompatibility(typeName, type); } return type; }
private static void CheckCompatibility(TypeName typeName, Type type) { try { TypeName loadedTypeName = TypeNameParser.Parse(type.AssemblyQualifiedName); if (!typeName.IsCompatible(loadedTypeName)) throw new PersistenceException(String.Format( "Serialized type is incompatible with available type: serialized: {0}, loaded: {1}", typeName.ToString(true, true), type.AssemblyQualifiedName)); if (typeName.IsNewerThan(loadedTypeName)) throw new PersistenceException(String.Format( "Serialized type is newer than available type: serialized: {0}, loaded: {1}", typeName.ToString(true, true), type.AssemblyQualifiedName)); } catch (PersistenceException) { throw; } catch (Exception e) { Logger.Warn(String.Format( "Could not perform version check requested type was {0} while loaded type is {1}:", typeName.ToString(true, true), type.AssemblyQualifiedName), e); } }
private static Type LoadWithPartialName(TypeName typeName) { try { #pragma warning disable 0618 Assembly a = Assembly.LoadWithPartialName(typeName.AssemblyName); // the suggested Assembly.Load() method fails to load assemblies outside the GAC #pragma warning restore 0618 return a.GetType(typeName.ToString(false, false), true); } catch (Exception) { throw new PersistenceException(String.Format( "Could not load type \"{0}\"", typeName.ToString(true, true))); } }