{"record":{"id":"cde1dbc35233d078","repo":"EllanJiang/GameFramework","slug":"download-manager-is-invalid","errorCode":null,"errorMessage":"Download manager is invalid.","messagePattern":"Download manager is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceUpdater.cs","lineNumber":273,"sourceCode":"                    m_DownloadManager.DownloadUpdate -= OnDownloadUpdate;\n                    m_DownloadManager.DownloadSuccess -= OnDownloadSuccess;\n                    m_DownloadManager.DownloadFailure -= OnDownloadFailure;\n                }\n\n                m_UpdateWaitingInfo.Clear();\n                m_UpdateCandidateInfo.Clear();\n                m_CachedFileSystemsForGenerateReadWriteVersionList.Clear();\n            }\n\n            /// <summary>\n            /// 设置下载管理器。\n            /// </summary>\n            /// <param name=\"downloadManager\">下载管理器。</param>\n            public void SetDownloadManager(IDownloadManager downloadManager)\n            {\n                if (downloadManager == null)\n                {\n                    throw new GameFrameworkException(\"Download manager is invalid.\");\n                }\n\n                m_DownloadManager = downloadManager;\n                m_DownloadManager.DownloadStart += OnDownloadStart;\n                m_DownloadManager.DownloadUpdate += OnDownloadUpdate;\n                m_DownloadManager.DownloadSuccess += OnDownloadSuccess;\n                m_DownloadManager.DownloadFailure += OnDownloadFailure;\n            }\n\n            /// <summary>\n            /// 增加资源更新。\n            /// </summary>\n            /// <param name=\"resourceName\">资源名称。</param>\n            /// <param name=\"fileSystemName\">资源所在的文件系统名称。</param>\n            /// <param name=\"loadType\">资源加载方式。</param>\n            /// <param name=\"length\">资源大小。</param>\n            /// <param name=\"hashCode\">资源哈希值。</param>\n            /// <param name=\"compressedLength\">压缩后大小。</param>","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceUpdater.cs#L255-L291","documentation":"ResourceManager.SetDownloadManager throws this when the provided IDownloadManager reference is null. The updater requires a download manager to fetch remote resource updates and wires event handlers (DownloadStart/Update/Success) to it, so a null reference is rejected up front.","triggerScenarios":"Calling SetDownloadManager before the DownloadManager component was added/initialized, passing null explicitly, or a DI/GetComponent call that returned null (e.g. missing component on the GameObject).","commonSituations":"Unity initialization order issues where the resource manager is set up before the download manager; forgetting to add the DownloadManager component to the game framework GameObject; typo in component lookup.","solutions":["Create/add the DownloadManager component and pass the non-null instance","Ensure initialization order: download manager exists and is initialized before SetDownloadManager","Verify your service locator / GetComponent call actually returns an instance"],"exampleFix":"// before\nresourceManager.SetDownloadManager(m_GameEntry.GetComponent<DownloadManager>()); // null if missing\n// after\nvar dm = m_GameEntry.GetComponent<DownloadManager>();\nif (dm == null) { dm = m_GameEntry.AddComponent<DownloadManager>(); }\nresourceManager.SetDownloadManager(dm);","handlingStrategy":"validation","validationCode":"if (downloadManager == null) { downloadManager = AddOrGetComponent<DownloadManager>(); }","typeGuard":"bool HasDownloadManager(IDownloadManager dm) => dm != null;","tryCatchPattern":"try { resourceManager.SetDownloadManager(dm); } catch (GameFrameworkException ex) { Log.Error(\"DownloadManager not initialized: \" + ex.Message); }","preventionTips":["Initialize the DownloadManager component before the ResourceManager","Verify framework component creation order in your game entry code","Assert component lookups (GetComponent) return non-null during bootstrap"],"tags":["csharp","gameframework","null-argument","initialization"],"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"}