diff --git a/src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs b/src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs index f0029db4827..4280012e60e 100644 --- a/src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs +++ b/src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs @@ -74,33 +74,35 @@ internal ContentTypeReader[] LoadAssetReaders(ContentReader reader, int typeRead int readerTypeVersion = reader.ReadInt32(); ContentTypeReader typeReader; + Type typeReaderType; if (!_contentTypeReadersCache.ContainsKey(readerTypeName)) { - Type typeReaderType = ResolveReaderType(readerTypeName); + typeReaderType = ResolveReaderType(readerTypeName); _contentTypeReadersCache.Add(readerTypeName, typeReaderType); + } + else + { + typeReaderType = _contentTypeReadersCache[readerTypeName]; + } - System.Diagnostics.Debug.Assert(!_contentReadersCache.ContainsKey(typeReaderType)); - + if (!_contentReadersCache.ContainsKey(typeReaderType)) + { typeReader = typeReaderType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; needsInitialize[i] = true; _contentReadersCache.Add(typeReaderType, typeReader); - - if (readerTypeVersion != typeReader.TypeVersion) - { - throw new ContentLoadException( - String.Format("{0} of TypeVersion {1} does not match reader of TypeVersion {2}.", - typeReader.TargetType.Name, readerTypeVersion, typeReader.TypeVersion)); - } } else { - Type typeReaderType = _contentTypeReadersCache[readerTypeName]; - - System.Diagnostics.Debug.Assert(_contentReadersCache.ContainsKey(typeReaderType)); - typeReader = _contentReadersCache[typeReaderType]; } + if (readerTypeVersion != typeReader.TypeVersion) + { + throw new ContentLoadException( + String.Format("{0} of TypeVersion {1} does not match reader of TypeVersion {2}.", + typeReader.TargetType.Name, readerTypeVersion, typeReader.TypeVersion)); + } + contentReaders[i] = typeReader;