{"record":{"id":"93cd497d74f535ec","repo":"MonoGame/MonoGame","slug":"this-does-not-appear-to-be-a-monogame-mgfx-file","errorCode":null,"errorMessage":"This does not appear to be a MonoGame MGFX file!","messagePattern":"This does not appear to be a MonoGame MGFX file!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework/Graphics/Effect/Effect.cs","lineNumber":174,"sourceCode":"                }\n            }\n\n            // Clone it.\n            _isClone = true;\n            Clone(cloneSource);\n        }\n\n        private MGFXHeader ReadHeader(byte[] effectCode, int index)\n        {\n            MGFXHeader header;\n            header.Signature = BitConverter.ToInt32(effectCode, index); index += 4;\n            header.Version = (int)effectCode[index++];\n            header.Profile = (int)effectCode[index++];\n            header.EffectKey = BitConverter.ToInt32(effectCode, index); index += 4;\n            header.HeaderSize = 10;\n\n            if (header.Signature != MGFXHeader.MGFXSignature)\n                throw new Exception(\"This does not appear to be a MonoGame MGFX file!\");\n            if (header.Version < MGFXHeader.MGFXMinVersion)\n                throw new Exception(\"This MGFX effect is for an older release of MonoGame and needs to be rebuilt.\");\n            if (header.Version > MGFXHeader.MGFXVersion)\n                throw new Exception(\"This MGFX effect seems to be for a newer release of MonoGame.\");\n\n            if (header.Profile != Shader.Profile)\n                throw new Exception(\"This MGFX effect was built for a different platform!\");          \n            \n            return header;\n        }\n\n        /// <summary>\n        /// Clone the source into this existing object.\n        /// </summary>\n        /// <remarks>\n        /// Note this is not overloaded in derived classes on purpose.  This is\n        /// only a reason this exists is for caching effects.\n        /// </remarks>","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework/Graphics/Effect/Effect.cs#L156-L192","documentation":"Thrown (plain Exception) by Effect.ReadHeader when the first 4 bytes (header.Signature) do not equal MGFXHeader.MGFXSignature. The byte blob is not recognized as an MGFX file at all — it is the wrong format, garbage, or a file with an unrelated magic number.","triggerScenarios":"Passing a non-MGFX byte array to Effect(device, byte[], ...): an .xnb, a raw .fx HLSL source, a PNG, or random bytes. The signature check is the very first validation after reading the header fields.","commonSituations":"Loading a raw HLSL .fx file instead of a compiled .mgfxo; pointing at the wrong asset; a content pipeline that emitted XNB where MGFX was expected; byte-order/endianness issues on big-endian platforms.","solutions":["Compile the .fx to .mgfxo with the 2MGFX compiler (mgfxc) for your platform before loading.","Load compiled effects through the content pipeline / Content.Load<Effect>.","Confirm the file is an MGFX file (correct magic) and is being read from offset 0."],"exampleFix":"// before\nvar bytes = File.ReadAllBytes(\"MyShader.fx\"); // raw HLSL source, wrong magic\nnew Effect(device, bytes, 0, bytes.Length); // throws\n\n// after\n// compile first: mgfxc MyShader.fx MyShader.mgfxo /profile:OpenGL\nvar bytes = File.ReadAllBytes(\"MyShader.mgfxo\");\nnew Effect(device, bytes, 0, bytes.Length);","handlingStrategy":"validation","validationCode":"// verify the MGFX magic before constructing\nvar sig = BitConverter.ToInt32(effectCode, 0);\nif (sig != MGFXHeader.MGFXSignature) // 0x5846474D 'MGFX'\n    throw new InvalidDataException(\"Not an MGFX file.\");\nnew Effect(device, effectCode, 0, effectCode.Length);","typeGuard":null,"tryCatchPattern":"try { new Effect(device, bytes, 0, bytes.Length); }\ncatch (Exception ex) when (ex.Message.Contains(\"MGFX file\"))\n{ Log.Error(\"Wrong asset format — expected a compiled .mgfxo.\"); throw; }","preventionTips":["Compile .fx to .mgfxo with mgfxc/2MGFX before loading.","Load effects through the content pipeline.","Confirm the file magic at offset 0 before parsing."],"tags":["monogame","effect","mgfx","file-format"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}