{"record":{"id":"bc802b11c559b039","repo":"EllanJiang/GameFramework","slug":"file-system-is-invalid","errorCode":null,"errorMessage":"File system is invalid.","messagePattern":"File system is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystemManager.cs","lineNumber":236,"sourceCode":"            {\n                fileSystemStream.Close();\n                throw new GameFrameworkException(Utility.Text.Format(\"Load file system '{0}' failure.\", fullPath));\n            }\n\n            m_FileSystems.Add(fullPath, fileSystem);\n            return fileSystem;\n        }\n\n        /// <summary>\n        /// 销毁文件系统。\n        /// </summary>\n        /// <param name=\"fileSystem\">要销毁的文件系统。</param>\n        /// <param name=\"deletePhysicalFile\">是否删除文件系统对应的物理文件。</param>\n        public void DestroyFileSystem(IFileSystem fileSystem, bool deletePhysicalFile)\n        {\n            if (fileSystem == null)\n            {\n                throw new GameFrameworkException(\"File system is invalid.\");\n            }\n\n            string fullPath = fileSystem.FullPath;\n            ((FileSystem)fileSystem).Shutdown();\n            m_FileSystems.Remove(fullPath);\n\n            if (deletePhysicalFile && File.Exists(fullPath))\n            {\n                File.Delete(fullPath);\n            }\n        }\n\n        /// <summary>\n        /// 获取所有文件系统集合。\n        /// </summary>\n        /// <returns>获取的所有文件系统集合。</returns>\n        public IFileSystem[] GetAllFileSystems()\n        {","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystemManager.cs#L218-L254","documentation":"FileSystemManager.DestroyFileSystem throws this when the fileSystem argument is null. Destroying requires an IFileSystem instance to look up its full path and shut it down; a null reference is rejected immediately.","triggerScenarios":"Calling DestroyFileSystem(null, deletePhysicalFile) - often the result of a Create/Load call that failed earlier and returned null (or threw) while the variable was still passed onward.","commonSituations":"Caching the result of CreateFileSystem/LoadFileSystem without checking for the earlier exception; tracking file systems in fields that were never assigned; cleanup code running after a failed initialization.","solutions":["Null-check the IFileSystem before calling DestroyFileSystem and skip destruction when null.","Fix the earlier Create/Load failure that left the reference null.","Ensure Shutdown() (which destroys all file systems) is not mixed with manual DestroyFileSystem calls on already-destroyed instances."],"exampleFix":"// before\nfileSystemManager.DestroyFileSystem(fileSystem, false); // NRE if null\n// after\nif (fileSystem != null)\n    fileSystemManager.DestroyFileSystem(fileSystem, false);","handlingStrategy":"type-guard","validationCode":"if (fileSystem == null) return; // nothing to destroy","typeGuard":"bool CanDestroy(IFileSystem fs) => fs != null;","tryCatchPattern":"try { manager.DestroyFileSystem(fs, deletePhysicalFile); }\ncatch (GameFrameworkException ex) when (ex.Message == \"File system is invalid.\") { Log.Warning(\"DestroyFileSystem called with null.\"); }","preventionTips":["Null-check file system references before cleanup calls.","Track created file systems in a collection so references are never null at teardown.","Prefer manager.Shutdown() for whole-manager teardown instead of per-instance destroys on possibly-null handles."],"tags":["filesystem","null-argument","gameframework"],"backgroundTag":"null-argument","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"}