MonoGame/MonoGame · error · ContentLoadException
Resource is not in binary format
Error message
Resource is not in binary format
What it means
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.
Source
Thrown at MonoGame.Framework/Content/ResourceContentManager.cs:52
/// <summary>
/// Opens a stream for reading the specified resource.
/// Derived classes can replace this to implement pack files or asset compression.
/// </summary>
/// <param name="assetName">The name of the asset being read.</param>
/// <exception cref="ContentLoadException">
/// Error loading <paramref name="assetName"/>.
/// The resource was not a binary resource, or the resource was not found.
/// </exception>
protected override System.IO.Stream OpenStream(string assetName)
{
object obj = this.resource.GetObject(assetName);
if (obj == null)
{
throw new ContentLoadException("Resource not found");
}
if (!(obj is byte[]))
{
throw new ContentLoadException("Resource is not in binary format");
}
return new MemoryStream(obj as byte[]);
}
}
}
View on GitHub (pinned to 1d71bbd0ff)
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.
Example fix
// before: .resx holds 'Font' as a System.Drawing.Bitmap -> throws 272
var font = Content.Load<SpriteFont>("Font");
// after: embed the compiled .xnb file as a byte[] resource named 'Font'
var font = Content.Load<SpriteFont>("Font"); Defensive patterns
Strategy: type-guard
Validate before calling
// Verify the resource is a byte[] before letting OpenStream run. object obj = resourceManager.GetObject(assetName); if (!(obj is byte[])) return; // not a binary XNB blob
Type guard
static bool IsBinaryResource(ResourceManager rm, string name) => rm.GetObject(name) is byte[];
Try / catch
try { var tex = Content.Load<Texture2D>("Font"); }
catch (ContentLoadException ex) when (ex.Message == "Resource is not in binary format")
{ /* re-embed the .xnb as a byte[] resource */ } Prevention
- 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.
When it happens
Trigger: The resource key resolves to a non-binary embedded resource (a string, Image, etc.) instead of the raw XNB byte[].
Common situations: .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.
Related errors
- Resource not found
- resource
- The content file was not found.
- The directory was not found.
- Opening stream error.
AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13).
Data as JSON: /api/errors/899ccbef42d26532.
Report an issue: GitHub.