예제 #1
0
 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);
     }
 }
예제 #2
0
        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)));
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
 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;
 }
예제 #5
0
 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);
   }
 }
예제 #6
0
    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)));
      }
    }