Exemplo n.º 1
0
 public static Type LoadTypeByName(string name, bool disallowUnsafeTypes, ITypeFilter typeFilter)
 {
     if (disallowUnsafeTypes)
     {
         if (IsDisallowedType(name))
         {
             throw new EvilDeserializationException("Unsafe Type Deserialization Detected!", name);
         }
         if (!typeFilter.IsAllowed(name))
         {
             throw new UserEvilDeserializationException("Unsafe Type Deserialization Detected!", name);
         }
     }
     try
     {
         // Try to load type name using strict version to avoid possible conflicts
         // i.e. if there are different version available in GAC and locally
         var typename = ToQualifiedAssemblyName(name, ignoreAssemblyVersion: false);
         var type     = Type.GetType(typename, true);
         if (disallowUnsafeTypes && UnsafeInheritanceCheck(type))
         {
             throw new EvilDeserializationException(
                       "Unsafe Type Deserialization Detected!", name);
         }
         return(type);
     }
     catch (IOException)
     {
         var typename = ToQualifiedAssemblyName(name, ignoreAssemblyVersion: true);
         var type     = Type.GetType(typename, true);
         if (disallowUnsafeTypes && UnsafeInheritanceCheck(type))
         {
             throw new EvilDeserializationException(
                       "Unsafe Type Deserialization Detected!", name);
         }
         return(type);
     }
 }