dotnet/wpf · error · ApplicationException
SR.ResourceTooBig (ResourceTooBig: , max )
Error message
SR.ResourceTooBig (ResourceTooBig: {_sourcePath}, max {Int32.MaxValue}) What it means
ResourcesGenerator's LazyFileStream wraps a resource file opened for reading and, because resource data is later copied into int-sized buffers, limits the file to Int32.MaxValue bytes. If the source stream is longer, it throws ApplicationException with SR.ResourceTooBig naming the file and the 2GB limit.
Solutions
- Remove or shrink the oversized resource file so it is under 2 GB.
- Exclude large assets from the resource list and load them from disk at runtime instead.
- Check for accidentally included build outputs (e.g. a huge .resources or database file) in the resource items.
- If truly needed, split the content into multiple resources or store it outside the assembly.
Example fix
<!-- before --> <Resource Include="Assets\huge-video.mp4" /> <!-- after --> <!-- copy file to output dir and load at runtime --> <None Include="Assets\huge-video.mp4" CopyToOutputDirectory="PreserveNewest" />
Defensive patterns
Strategy: validation
Validate before calling
var fi = new FileInfo(resourcePath);
if (fi.Length > int.MaxValue)
throw new InvalidOperationException($"Resource {resourcePath} exceeds 2GB in-process limit ({fi.Length} bytes)"); Try / catch
try { generator.Generate(...); }
catch (ApplicationException ex) when (ex.Message.Contains("ResourceTooBig") || ex.Message.Contains("too big"))
{ log.Error("Resource exceeds Int32.MaxValue; shrink or exclude it", ex); throw; } Prevention
- Audit Resource items for large binaries (video, DB dumps, build artifacts)
- Ship big assets as loose files, not embedded resources
- Set CI checks on resource file sizes
When it happens
Trigger: Building WPF .resources (.baml/resource embedding) where a source resource file (e.g. a large image, media, or .resources blob passed to GenerateResource/ResourceGenerating pipeline) exceeds 2,147,483,647 bytes.
Common situations: Projects that accidentally embed very large videos, high-resolution multi-gigabyte images, or stale build artifacts as resources.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- NotSupportedException
- SR.ApplicationShuttingDown
- SR.BamlIsNotSupportedOutsideOfApplicationResources
- SR.ChangingIdNotAllowed
- SR.ChangingTypeNotAllowed
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e3d4ada5ed5d50ce.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs:53
public LazyFileStream(string path)
{
_sourcePath = Path.GetFullPath(path);
}
private Stream SourceStream
{
get
{
if (_sourceStream == null)
{
_sourceStream = new FileStream(_sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read);
// limit size to System.Int32.MaxValue
long length = _sourceStream.Length;
if (length > (long)System.Int32.MaxValue)
{
throw new ApplicationException(SR.Format(SR.ResourceTooBig, _sourcePath, System.Int32.MaxValue));
}
}
return _sourceStream;
}
}
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return true; } }
public override bool CanWrite { get { return false; } }
public override void Flush() {}
public override long Length
{
get { return SourceStream.Length; }View on GitHub (pinned to 81131a70a4)