EllanJiang/GameFramework · error · GameFrameworkException

Resource manager is invalid.

Error message

Resource manager is invalid.

What it means

DataProvider requires an IResourceManager before it can load data assets. SetResourceManager validates the argument and throws GameFrameworkException when a null resource manager is passed. This is an internal setup-time guard invoked during DataProvider creation.

Solutions

  1. Ensure the Resource component (IResourceManager) is created and initialized before calling DataProvider.Create.
  2. Pass a valid, non-null IResourceManager instance to the create path.
  3. Check initialization order so DataProvider setup happens after Resource module setup.
  4. Log/inspect why the resource manager is null (failed startup, missing configuration).

Example fix

// before
dataProvider.Create(gameObject, null, dataProviderHelper);
// after
IResourceManager resourceManager = gameFramework.GetComponent<ResourceComponent>().ResourceManager;
if (resourceManager == null) { throw new InvalidOperationException("Resource component not initialized"); }
dataProvider.Create(gameObject, resourceManager, dataProviderHelper);
Defensive patterns

Strategy: validation

Validate before calling

if (resourceManager == null)
{
    throw new InvalidOperationException("IResourceManager must be created before DataProvider.Create");
}
dataProvider.Create(gameObject, resourceManager, dataProviderHelper);

Type guard

bool IsValidResourceManager(IResourceManager rm) => rm != null;

Prevention

When it happens

Trigger: Calling DataProvider.Create (or internal initialization) with a null IResourceManager argument, typically when the Resource component has not been initialized or the resourceManager variable was not assigned.

Common situations: GameFramework initialization order mistakes: creating a data provider before the Resource component is built; passing an uninitialized/failed-to-create resource manager; refactoring that removed resource manager construction.

Related errors


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

Appendix: source

Thrown at GameFramework/Base/DataProvider/DataProvider.cs:382

            {
                if (exception is GameFrameworkException)
                {
                    throw;
                }

                throw new GameFrameworkException(Utility.Text.Format("Can not parse data bytes with exception '{0}'.", exception), exception);
            }
        }

        /// <summary>
        /// 设置资源管理器。
        /// </summary>
        /// <param name="resourceManager">资源管理器。</param>
        internal void SetResourceManager(IResourceManager resourceManager)
        {
            if (resourceManager == null)
            {
                throw new GameFrameworkException("Resource manager is invalid.");
            }

            m_ResourceManager = resourceManager;
        }

        /// <summary>
        /// 设置数据提供者辅助器。
        /// </summary>
        /// <param name="dataProviderHelper">数据提供者辅助器。</param>
        internal void SetDataProviderHelper(IDataProviderHelper<T> dataProviderHelper)
        {
            if (dataProviderHelper == null)
            {
                throw new GameFrameworkException("Data provider helper is invalid.");
            }

            m_DataProviderHelper = dataProviderHelper;
        }

View on GitHub (pinned to d0c010b051)