{"record":{"id":"2a78f7045a63fc11","repo":"EllanJiang/GameFramework","slug":"max-file-count-is-invalid","errorCode":null,"errorMessage":"Max file count is invalid.","messagePattern":"Max file count is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":143,"sourceCode":"            {\n                return m_HeaderData.MaxFileCount;\n            }\n        }\n\n        /// <summary>\n        /// 创建文件系统。\n        /// </summary>\n        /// <param name=\"fullPath\">要创建的文件系统的完整路径。</param>\n        /// <param name=\"access\">要创建的文件系统的访问方式。</param>\n        /// <param name=\"stream\">要创建的文件系统的文件系统流。</param>\n        /// <param name=\"maxFileCount\">要创建的文件系统的最大文件数量。</param>\n        /// <param name=\"maxBlockCount\">要创建的文件系统的最大块数据数量。</param>\n        /// <returns>创建的文件系统。</returns>\n        public static FileSystem Create(string fullPath, FileSystemAccess access, FileSystemStream stream, int maxFileCount, int maxBlockCount)\n        {\n            if (maxFileCount <= 0)\n            {\n                throw new GameFrameworkException(\"Max file count is invalid.\");\n            }\n\n            if (maxBlockCount <= 0)\n            {\n                throw new GameFrameworkException(\"Max block count is invalid.\");\n            }\n\n            if (maxFileCount > maxBlockCount)\n            {\n                throw new GameFrameworkException(\"Max file count can not larger than max block count.\");\n            }\n\n            FileSystem fileSystem = new FileSystem(fullPath, access, stream);\n            fileSystem.m_HeaderData = new HeaderData(maxFileCount, maxBlockCount);\n            CalcOffsets(fileSystem);\n            Utility.Marshal.StructureToBytes(fileSystem.m_HeaderData, HeaderDataSize, s_CachedBytes);\n\n            try","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L125-L161","documentation":"FileSystem.Create validates that maxFileCount is a positive integer because the header must reserve space for at least one file entry. Zero or negative values are structurally impossible, so Create throws before writing the header.","triggerScenarios":"Calling FileSystem.Create(fullPath, access, stream, maxFileCount, maxBlockCount) with maxFileCount <= 0 — e.g. 0, or a value read from config that defaulted to 0.","commonSituations":"Config value for max files missing/empty and parsed to 0; arithmetic producing zero from an empty collection count; copy-paste passing the wrong parameter order so a smaller block count lands in the file count slot.","solutions":["Pass a positive maxFileCount reflecting the expected number of files (e.g. 16, 1024)","Validate config-driven values with a positive-number check before calling Create","Verify parameter order: the 4th argument is maxFileCount, the 5th is maxBlockCount","Choose headroom for growth since the header reserves fixed space for this many entries"],"exampleFix":"// before\nint maxFileCount = settings.MaxFiles; // may be 0\nvar fs = FileSystem.Create(path, access, stream, maxFileCount, maxBlocks);\n// after\nint maxFileCount = Math.Max(1, settings.MaxFiles);\nvar fs = FileSystem.Create(path, access, stream, maxFileCount, maxBlocks);","handlingStrategy":"validation","validationCode":"if (maxFileCount <= 0) throw new ArgumentOutOfRangeException(nameof(maxFileCount), maxFileCount, \"must be positive\");\nFileSystem.Create(fullPath, access, stream, maxFileCount, maxBlockCount);","typeGuard":"bool IsValidMaxFileCount(int n) => n > 0;","tryCatchPattern":"try { var fs = FileSystem.Create(path, access, stream, fc, bc); }\ncatch (GameFrameworkException ex) when (ex.Message == \"Max file count is invalid.\") { Log.Error($\"maxFileCount={fc} — check config source\"); }","preventionTips":["Validate config-driven capacity values at load time","Check argument order in Create calls (maxFileCount before maxBlockCount)","Pick file-count headroom since header space is fixed at creation"],"tags":["gameframework","filesystem","argument-validation"],"backgroundTag":"invalid-config-value","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}