EllanJiang/GameFramework · error · GameFrameworkException

Max file count is invalid.

Error message

Max file count is invalid.

What it means

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.

Solutions

  1. Pass a positive maxFileCount reflecting the expected number of files (e.g. 16, 1024)
  2. Validate config-driven values with a positive-number check before calling Create
  3. Verify parameter order: the 4th argument is maxFileCount, the 5th is maxBlockCount
  4. Choose headroom for growth since the header reserves fixed space for this many entries

Example fix

// before
int maxFileCount = settings.MaxFiles; // may be 0
var fs = FileSystem.Create(path, access, stream, maxFileCount, maxBlocks);
// after
int maxFileCount = Math.Max(1, settings.MaxFiles);
var fs = FileSystem.Create(path, access, stream, maxFileCount, maxBlocks);
Defensive patterns

Strategy: validation

Validate before calling

if (maxFileCount <= 0) throw new ArgumentOutOfRangeException(nameof(maxFileCount), maxFileCount, "must be positive");
FileSystem.Create(fullPath, access, stream, maxFileCount, maxBlockCount);

Type guard

bool IsValidMaxFileCount(int n) => n > 0;

Try / catch

try { var fs = FileSystem.Create(path, access, stream, fc, bc); }
catch (GameFrameworkException ex) when (ex.Message == "Max file count is invalid.") { Log.Error($"maxFileCount={fc} — check config source"); }

Prevention

When it happens

Trigger: Calling FileSystem.Create(fullPath, access, stream, maxFileCount, maxBlockCount) with maxFileCount <= 0 — e.g. 0, or a value read from config that defaulted to 0.

Common situations: 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.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/2a78f7045a63fc11. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/FileSystem/FileSystem.cs:143

            {
                return m_HeaderData.MaxFileCount;
            }
        }

        /// <summary>
        /// 创建文件系统。
        /// </summary>
        /// <param name="fullPath">要创建的文件系统的完整路径。</param>
        /// <param name="access">要创建的文件系统的访问方式。</param>
        /// <param name="stream">要创建的文件系统的文件系统流。</param>
        /// <param name="maxFileCount">要创建的文件系统的最大文件数量。</param>
        /// <param name="maxBlockCount">要创建的文件系统的最大块数据数量。</param>
        /// <returns>创建的文件系统。</returns>
        public static FileSystem Create(string fullPath, FileSystemAccess access, FileSystemStream stream, int maxFileCount, int maxBlockCount)
        {
            if (maxFileCount <= 0)
            {
                throw new GameFrameworkException("Max file count is invalid.");
            }

            if (maxBlockCount <= 0)
            {
                throw new GameFrameworkException("Max block count is invalid.");
            }

            if (maxFileCount > maxBlockCount)
            {
                throw new GameFrameworkException("Max file count can not larger than max block count.");
            }

            FileSystem fileSystem = new FileSystem(fullPath, access, stream);
            fileSystem.m_HeaderData = new HeaderData(maxFileCount, maxBlockCount);
            CalcOffsets(fileSystem);
            Utility.Marshal.StructureToBytes(fileSystem.m_HeaderData, HeaderDataSize, s_CachedBytes);

            try

View on GitHub (pinned to d0c010b051)