EllanJiang/GameFramework · error · GameFrameworkException

Resource manager is invalid.

Error message

Resource manager is invalid.

What it means

DataProviderCreator.Create<T>() throws GameFrameworkException('Resource manager is invalid.') when the resourceManager argument is null. The data provider needs an IResourceManager to load its data, so the factory refuses to construct one without it. This is fail-fast validation performed after the owner check.

Solutions

  1. Obtain the initialized IResourceManager (e.g. from the GameFramework entry/component) and pass it to Create<T>
  2. Ensure framework resource modules are initialized before creating data providers
  3. If using DI, verify IResourceManager is registered and the resolved instance is not null before calling Create

Example fix

// before
var provider = DataProviderCreator.Create<Player>(player, null, helper);
// after
IResourceManager resourceManager = GameFrameworkEntry.GetModule<ResourceManager>();
if (resourceManager == null) { throw new InvalidOperationException("ResourceManager not initialized"); }
var provider = DataProviderCreator.Create<Player>(player, resourceManager, helper);
Defensive patterns

Strategy: validation

Validate before calling

if (resourceManager == null) throw new ArgumentNullException(nameof(resourceManager));
DataProviderCreator.Create<T>(owner, resourceManager, helper);

Type guard

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

Try / catch

try
{
    var provider = DataProviderCreator.Create<T>(owner, resourceManager, helper);
}
catch (GameFrameworkException ex) when (ex.Message == "Resource manager is invalid.")
{
    // initialize framework resource module before creating providers
}

Prevention

When it happens

Trigger: Calling DataProviderCreator.Create<T>(owner, null, dataProviderHelper). Usually caused by the IResourceManager not having been built yet, a failed dependency-injection resolution, or passing the wrong variable (null) where the resource manager was intended.

Common situations: Calling Create before GameFramework's resource component/module is initialized; DI container failed to register or resolve IResourceManager; copying example code without obtaining the framework's resource manager instance first.

Related errors


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

Appendix: source

Thrown at GameFramework/Base/DataProvider/DataProviderCreator.cs:63

        /// <summary>
        /// 创建数据提供者。
        /// </summary>
        /// <typeparam name="T">数据提供者的持有者的类型。</typeparam>
        /// <param name="owner">数据提供者的持有者。</param>
        /// <param name="resourceManager">资源管理器。</param>
        /// <param name="dataProviderHelper">数据提供者辅助器。</param>
        /// <returns>创建的数据提供者。</returns>
        public static IDataProvider<T> Create<T>(T owner, IResourceManager resourceManager, IDataProviderHelper<T> dataProviderHelper)
        {
            if (owner == null)
            {
                throw new GameFrameworkException("Owner is invalid.");
            }

            if (resourceManager == null)
            {
                throw new GameFrameworkException("Resource manager is invalid.");
            }

            if (dataProviderHelper == null)
            {
                throw new GameFrameworkException("Data provider helper is invalid.");
            }

            DataProvider<T> dataProvider = new DataProvider<T>(owner);
            dataProvider.SetResourceManager(resourceManager);
            dataProvider.SetDataProviderHelper(dataProviderHelper);
            return dataProvider;
        }
    }
}

View on GitHub (pinned to d0c010b051)