private static Dictionary <string, Type> ReadTypeCache(XContainer rootNode) { var result = new Dictionary <string, Type>(); var typeNameManager = new TypeNameManager(); foreach (var typeNode in rootNode.Elements(XmlConstants.TYPE_CACHE).Elements(XmlConstants.ITEM)) { var keyAttrib = typeNode.Attribute(XmlConstants.KEY); var valueAttrib = typeNode.Attribute(XmlConstants.VALUE); if (keyAttrib == null || valueAttrib == null) { continue; } Type t; try { // This method is too strict to handle auto-incrementing versioned dll references, but is // needed to correctly grab core .Net Framework stuff and works faster for same-version dll files. t = Type.GetType(valueAttrib.Value); if (t == null) { // Try to found type in current appdomain. // This will work for dynamically loaded assemblies (e.g. via MEF). t = Type.GetType(valueAttrib.Value, name => AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(z => z.FullName == name.FullName), null); } if (t == null) { //check whether the needed object was moved to another assembly MovedTypes mt = new MovedTypes(); foreach (TypeMoveDefintion tc in mt.Types) { if (tc.IsApplicable(valueAttrib.Value)) { t = Type.GetType(tc.MoveType(valueAttrib.Value)); if (t != null) { break; } } } } } catch (FileLoadException) { // Attempting to load the fully qualified name failed. Search under more general terms // and see if we can find a valid assembly with the specified type. string updatedName = typeNameManager.UpdateTypename(valueAttrib.Value); t = Type.GetType(updatedName); } result.Add(keyAttrib.Value, t); } return(result); }
private static Dictionary <string, Type> ReadTypeCache(XElement rootNode) { Dictionary <string, Type> result = new Dictionary <string, Type>(); TypeNameManager typeNameManager = new TypeNameManager(); foreach (var typeNode in rootNode.Elements(XmlConstants.TYPE_CACHE).Elements(XmlConstants.ITEM)) { var keyAttrib = typeNode.Attribute(XmlConstants.KEY); var valueAttrib = typeNode.Attribute(XmlConstants.VALUE); if (keyAttrib == null || valueAttrib == null) { continue; } // string[] parts = valueAttrib.Value.Split(','); Type t; try { // This method is too strict to handle auto-incrementing versioned dll references, but is // needed to correctly grab core .Net Framework stuff and works faster for same-version dll files. t = Type.GetType(valueAttrib.Value); } catch (FileLoadException) { // Attempting to load the fully qualified name failed. Search under more general terms // and see if we can find a valid assembly with the specified type. string updatedName = typeNameManager.UpdateTypename(valueAttrib.Value); t = Type.GetType(updatedName); } result.Add(keyAttrib.Value, t); } return(result); }