{"record":{"id":"175e7972d4ba1a8a","repo":"MonoGame/MonoGame","slug":"it-seems-that-you-are-using-publishaot-and-trying","errorCode":null,"errorMessage":"It seems that you are using PublishAot and trying to load assets with a reflection-based serializer (which is not natively supported). To work around this error, call ContentTypeReaderManager.AddTypeCreator() in your Game constructor with the following type: {originalReaderTypeString}","messagePattern":"It seems that you are using PublishAot and trying to load assets with a reflection-based serializer \\(which is not natively supported\\)\\. To work around this error, call ContentTypeReaderManager\\.AddTypeCreator\\(\\) in your Game constructor with the following type: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework/Content/ContentTypeReaderManager.cs","lineNumber":183,"sourceCode":"                    {\n                        // Need to resolve namespace differences\n                        string readerTypeString = originalReaderTypeString;\n\n                        readerTypeString = PrepareType(readerTypeString);\n\n                        Type l_readerType = null;\n                        try\n                        {\n                            // This might fail in AOT context and we need to properly warn the user on what to do if it happens\n#pragma warning disable IL2057\n                            l_readerType = Type.GetType(readerTypeString);\n#pragma warning restore IL2057\n                        }\n                        catch (NotSupportedException e)\n                        {\n                            // This will not trigger on recent NativeAOT versions, it will crash later on GetDefaultConstructor() with a native access violation\n                            // but we keep this catch block for backward compatibility with older NativeAOT\n                            throw new NotSupportedException(\"It seems that you are using PublishAot and trying to load assets with a reflection-based serializer (which is not natively supported). To work around this error, call ContentTypeReaderManager.AddTypeCreator() in your Game constructor with the following type: \" + originalReaderTypeString);\n                        }\n\n                        if (l_readerType != null)\n                        {\n                            ContentTypeReader typeReader;\n                            if (!_contentReadersCache.TryGetValue(l_readerType, out typeReader))\n                            {\n                                try\n                                {\n                                    typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader;\n                                }\n                                catch (TargetInvocationException ex)\n                                {\n                                    // If you are getting here, the Mono runtime is most likely not able to JIT the type.\n                                    // In particular, MonoTouch needs help instantiating types that are only defined in strings in Xnb files.\n                                    throw new InvalidOperationException(\n                                        \"Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() \" +\n                                        \"with the following failed type string: \" + originalReaderTypeString, ex);","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework/Content/ContentTypeReaderManager.cs#L165-L201","documentation":"When resolving a reader type string via Type.GetType(readerTypeString), older NativeAOT runtimes throw NotSupportedException because reflection-based type loading is unsupported under AOT. MonoGame catches it and re-throws a descriptive NotSupportedException instructing you to call ContentTypeReaderManager.AddTypeCreator for the named type string.","triggerScenarios":"Publishing with PublishAot / NativeAOT and loading an XNB asset whose reader type is not pre-registered, so Type.GetType fails at runtime.","commonSituations":"Moving a project to PublishAot or enabling trimming without registering all required content readers; loading content whose reader type only appears as a string in the XNB.","solutions":["Call ContentTypeReaderManager.AddTypeCreator(typeof(TheReader).FullName, () => new TheReader()) in your Game constructor for the type named in the message.","Keep reflection-based serialization off under AOT by pre-registering every reader you load.","Note that many common readers are already auto-registered in the static constructor; only non-standard ones need manual registration."],"exampleFix":"// before: Content.Load throws 266 under PublishAot\nvar tex = Content.Load<Texture2D>(\"sprite\");\n\n// after: register the missing reader type in the Game constructor\nContentTypeReaderManager.AddTypeCreator(\n    \"Microsoft.Xna.Framework.Content.Texture2DReader\",\n    () => new Texture2DReader());","handlingStrategy":"validation","validationCode":"// Pre-register every content reader you intend to load under AOT.\nContentTypeReaderManager.AddTypeCreator(typeof(MyReader).FullName, () => new MyReader());","typeGuard":null,"tryCatchPattern":"try { var asset = Content.Load<T>(\"x\"); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"PublishAot\"))\n{ var typeName = ExtractTypeName(ex); ContentTypeReaderManager.AddTypeCreator(typeName, () => /*new reader*/); }","preventionTips":["Pre-register all content readers before the first Content.Load under PublishAot.","Keep a list of reader types and register them in the Game constructor.","Remember common readers are auto-registered; only non-standard ones need manual work."],"tags":["content","aot","nativeaot","trimming","reflection"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}