{"record":{"id":"e3d4ada5ed5d50ce","repo":"dotnet/wpf","slug":"sr-resourcetoobig-resourcetoobig-sourcepath-max-int32","errorCode":null,"errorMessage":"SR.ResourceTooBig (ResourceTooBig: {_sourcePath}, max {Int32.MaxValue})","messagePattern":"SR\\.ResourceTooBig \\(ResourceTooBig: (.+?), max (.+?)\\)","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs","lineNumber":53,"sourceCode":"\n            public LazyFileStream(string path)\n            {\n                _sourcePath = Path.GetFullPath(path);\n            }\n\n            private Stream SourceStream\n            {\n                get\n                {\n                    if (_sourceStream == null)\n                    {\n                        _sourceStream = new FileStream(_sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read);\n\n                        // limit size to System.Int32.MaxValue\n                        long length = _sourceStream.Length;\n                        if (length > (long)System.Int32.MaxValue)\n                        {\n                            throw new ApplicationException(SR.Format(SR.ResourceTooBig, _sourcePath, System.Int32.MaxValue));\n                        }\n\n                    }\n                    return _sourceStream;\n                }\n            }\n\n            public override bool CanRead { get { return true; } }\n\n            public override bool CanSeek { get { return true; } }\n\n            public override bool CanWrite { get { return false; } }\n\n            public override void Flush() {}\n\n            public override long Length\n            {\n                get { return SourceStream.Length; }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs#L35-L71","documentation":"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.","triggerScenarios":"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.","commonSituations":"Projects that accidentally embed very large videos, high-resolution multi-gigabyte images, or stale build artifacts as resources.","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."],"exampleFix":"<!-- before -->\n<Resource Include=\"Assets\\huge-video.mp4\" />\n<!-- after -->\n<!-- copy file to output dir and load at runtime -->\n<None Include=\"Assets\\huge-video.mp4\" CopyToOutputDirectory=\"PreserveNewest\" />","handlingStrategy":"validation","validationCode":"var fi = new FileInfo(resourcePath);\nif (fi.Length > int.MaxValue)\n    throw new InvalidOperationException($\"Resource {resourcePath} exceeds 2GB in-process limit ({fi.Length} bytes)\");","typeGuard":null,"tryCatchPattern":"try { generator.Generate(...); }\ncatch (ApplicationException ex) when (ex.Message.Contains(\"ResourceTooBig\") || ex.Message.Contains(\"too big\"))\n{ log.Error(\"Resource exceeds Int32.MaxValue; shrink or exclude it\", ex); throw; }","preventionTips":["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"],"tags":["file-size-limit","resources","wpf-build"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}