{"record":{"id":"899ccbef42d26532","repo":"MonoGame/MonoGame","slug":"resource-is-not-in-binary-format","errorCode":null,"errorMessage":"Resource is not in binary format","messagePattern":"Resource is not in binary format","errorType":"exception","errorClass":"ContentLoadException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework/Content/ResourceContentManager.cs","lineNumber":52,"sourceCode":"        /// <summary>\n        /// Opens a stream for reading the specified resource.\n        /// Derived classes can replace this to implement pack files or asset compression.\n        /// </summary>\n        /// <param name=\"assetName\">The name of the asset being read.</param>\n        /// <exception cref=\"ContentLoadException\">\n        /// Error loading <paramref name=\"assetName\"/>.\n        /// The resource was not a binary resource, or the resource was not found.\n        /// </exception>\n        protected override System.IO.Stream OpenStream(string assetName)\n        {\n            object obj = this.resource.GetObject(assetName);\n            if (obj == null)\n            {\n                throw new ContentLoadException(\"Resource not found\");\n            }\n            if (!(obj is byte[]))\n            {\n                throw new ContentLoadException(\"Resource is not in binary format\");\n            }\n            return new MemoryStream(obj as byte[]);\n        }\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":58,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework/Content/ResourceContentManager.cs#L34-L58","documentation":"After fetching the resource object, OpenStream requires it be a byte[] (the raw XNB binary). If the object exists but is not a byte array (e.g. a string, Bitmap, or typed object), MonoGame throws ContentLoadException(\"Resource is not in binary format\"). The resource must contain the serialized XNB bytes, not a typed value.","triggerScenarios":"The resource key resolves to a non-binary embedded resource (a string, Image, etc.) instead of the raw XNB byte[].","commonSituations":".resx embedded the asset as a typed object rather than as a binary XNB blob; wrong resource embedding mode; designer-typed resource overriding the byte stream.","solutions":["Embed the asset as a binary XNB byte[] resource (the raw .xnb file bytes).","Re-export resources so each asset is a byte[] entry, not a typed object.","Verify with ResourceManager.GetObject that the value is a byte[] before loading."],"exampleFix":"// before: .resx holds 'Font' as a System.Drawing.Bitmap -> throws 272\nvar font = Content.Load<SpriteFont>(\"Font\");\n\n// after: embed the compiled .xnb file as a byte[] resource named 'Font'\nvar font = Content.Load<SpriteFont>(\"Font\");","handlingStrategy":"type-guard","validationCode":"// Verify the resource is a byte[] before letting OpenStream run.\nobject obj = resourceManager.GetObject(assetName);\nif (!(obj is byte[])) return; // not a binary XNB blob","typeGuard":"static bool IsBinaryResource(ResourceManager rm, string name) => rm.GetObject(name) is byte[];","tryCatchPattern":"try { var tex = Content.Load<Texture2D>(\"Font\"); }\ncatch (ContentLoadException ex) when (ex.Message == \"Resource is not in binary format\")\n{ /* re-embed the .xnb as a byte[] resource */ }","preventionTips":["Embed assets as raw .xnb byte[] resources, not typed objects.","Use IsBinaryResource to validate before loading during development.","Re-export resources with the binary embedding mode."],"tags":["content","resource","binary","resource-manager"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}