EllanJiang/GameFramework · error · GameFrameworkException

Data provider helper is invalid.

Error message

Data provider helper is invalid.

What it means

DataProvider needs an IDataProviderHelper<T> that knows how to read data assets. SetDataProviderHelper throws GameFrameworkException if the helper passed in is null, because without a helper no data can ever be read. This guard runs during DataProvider creation.

Solutions

  1. Pass a non-null IDataProviderHelper<T> implementation (default or custom) when creating the DataProvider.
  2. Verify your custom helper class is instantiated, not just its type.
  3. Check that any helper factory/dependency injection actually returns an instance.
  4. Initialize helpers before the DataProvider create call in the startup sequence.

Example fix

// before
dataProvider.Create(gameObject, resourceManager, null);
// after
IDataProviderHelper<DataProviderTest> helper = new DataProviderHelper();
dataProvider.Create(gameObject, resourceManager, helper);
Defensive patterns

Strategy: validation

Validate before calling

IDataProviderHelper<T> helper = new DefaultDataProviderHelper(); // or your custom helper
if (helper == null)
{
    throw new InvalidOperationException("DataProviderHelper must not be null");
}
dataProvider.Create(gameObject, resourceManager, helper);

Type guard

bool IsValidHelper<T>(IDataProviderHelper<T> helper) => helper != null;

Prevention

When it happens

Trigger: Calling DataProvider.Create (or internal init) with a null dataProviderHelper, e.g. forgetting to construct a custom IDataProviderHelper<T> implementation or passing a failed helper instantiation.

Common situations: Forgetting to register a data provider helper when wiring the data provider; a helper factory returning null; refactoring away the helper class while still calling Create.

Related errors


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

Appendix: source

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

        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;
        }

        private void LoadAssetSuccessCallback(string dataAssetName, object dataAsset, float duration, object userData)
        {
            try
            {
                if (!m_DataProviderHelper.ReadData(m_Owner, dataAssetName, dataAsset, userData))
                {
                    throw new GameFrameworkException(Utility.Text.Format("Load data failure in data provider helper, data asset name '{0}'.", dataAssetName));
                }

                if (m_ReadDataSuccessEventHandler != null)
                {
                    ReadDataSuccessEventArgs loadDataSuccessEventArgs = ReadDataSuccessEventArgs.Create(dataAssetName, duration, userData);
                    m_ReadDataSuccessEventHandler(this, loadDataSuccessEventArgs);

View on GitHub (pinned to d0c010b051)