MonoGame/MonoGame · error · Exception
This does not appear to be a MonoGame MGFX file!
Error message
This does not appear to be a MonoGame MGFX file!
What it means
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.
Source
Thrown at MonoGame.Framework/Graphics/Effect/Effect.cs:174
}
}
// Clone it.
_isClone = true;
Clone(cloneSource);
}
private MGFXHeader ReadHeader(byte[] effectCode, int index)
{
MGFXHeader header;
header.Signature = BitConverter.ToInt32(effectCode, index); index += 4;
header.Version = (int)effectCode[index++];
header.Profile = (int)effectCode[index++];
header.EffectKey = BitConverter.ToInt32(effectCode, index); index += 4;
header.HeaderSize = 10;
if (header.Signature != MGFXHeader.MGFXSignature)
throw new Exception("This does not appear to be a MonoGame MGFX file!");
if (header.Version < MGFXHeader.MGFXMinVersion)
throw new Exception("This MGFX effect is for an older release of MonoGame and needs to be rebuilt.");
if (header.Version > MGFXHeader.MGFXVersion)
throw new Exception("This MGFX effect seems to be for a newer release of MonoGame.");
if (header.Profile != Shader.Profile)
throw new Exception("This MGFX effect was built for a different platform!");
return header;
}
/// <summary>
/// Clone the source into this existing object.
/// </summary>
/// <remarks>
/// Note this is not overloaded in derived classes on purpose. This is
/// only a reason this exists is for caching effects.
/// </remarks>View on GitHub (pinned to 1d71bbd0ff)
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.
Example fix
// before
var bytes = File.ReadAllBytes("MyShader.fx"); // raw HLSL source, wrong magic
new Effect(device, bytes, 0, bytes.Length); // throws
// after
// compile first: mgfxc MyShader.fx MyShader.mgfxo /profile:OpenGL
var bytes = File.ReadAllBytes("MyShader.mgfxo");
new Effect(device, bytes, 0, bytes.Length); Defensive patterns
Strategy: validation
Validate before calling
// verify the MGFX magic before constructing
var sig = BitConverter.ToInt32(effectCode, 0);
if (sig != MGFXHeader.MGFXSignature) // 0x5846474D 'MGFX'
throw new InvalidDataException("Not an MGFX file.");
new Effect(device, effectCode, 0, effectCode.Length); Try / catch
try { new Effect(device, bytes, 0, bytes.Length); }
catch (Exception ex) when (ex.Message.Contains("MGFX file"))
{ Log.Error("Wrong asset format — expected a compiled .mgfxo."); throw; } Prevention
- Compile .fx to .mgfxo with mgfxc/2MGFX before loading.
- Load effects through the content pipeline.
- Confirm the file magic at offset 0 before parsing.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The MGFX effect code was not parsed correctly.
- This MGFX effect is for an older release of MonoGame and nee
- This MGFX effect seems to be for a newer release of MonoGame
- This MGFX effect was built for a different platform!
- Invalid file signature
AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13).
Data as JSON: /api/errors/93cd497d74f535ec.
Report an issue: GitHub.