EllanJiang/GameFramework · error · GameFrameworkException

Type name is invalid.

Error message

Type name is invalid.

What it means

Utility.Assembly.GetType looks up a type by name among registered assemblies, using a cache. The type name is required, and this exception is thrown when the supplied name is null or the empty string.

Solutions

  1. Validate the type name is non-empty before calling GetType
  2. Fix the configuration/data source that produced the blank name
  3. Check upstream string parsing (Split, Substring) that may yield an empty string
  4. Add a null/empty guard or default value at the config-loading boundary

Example fix

// before
string typeName = config.TypeName; // may be ""
Type t = Utility.Assembly.GetType(typeName);
// after
if (string.IsNullOrEmpty(config.TypeName)) throw new ArgumentException("TypeName missing in config");
Type t = Utility.Assembly.GetType(config.TypeName);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(typeName)) throw new ArgumentException("typeName is required", nameof(typeName));

Type guard

bool IsValidTypeName(string typeName) => !string.IsNullOrEmpty(typeName);

Try / catch

try { var t = Utility.Assembly.GetType(typeName); } catch (GameFrameworkException ex) { Log.Error($"Invalid type name '{typeName}'"); }

Prevention

When it happens

Trigger: Calling Utility.Assembly.GetType(null) or GetType(""); passing a config-loaded type name that failed to deserialize into a non-empty string.

Common situations: Data-table/procedure type names read from config where the field is missing; string.Split or parsing producing an empty string; renamed type entries left blank in configuration.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Utility/Utility.Assembly.cs:79

                }

                results.Clear();
                foreach (System.Reflection.Assembly assembly in s_Assemblies)
                {
                    results.AddRange(assembly.GetTypes());
                }
            }

            /// <summary>
            /// 获取已加载的程序集中的指定类型。
            /// </summary>
            /// <param name="typeName">要获取的类型名。</param>
            /// <returns>已加载的程序集中的指定类型。</returns>
            public static Type GetType(string typeName)
            {
                if (string.IsNullOrEmpty(typeName))
                {
                    throw new GameFrameworkException("Type name is invalid.");
                }

                Type type = null;
                if (s_CachedTypes.TryGetValue(typeName, out type))
                {
                    return type;
                }

                type = Type.GetType(typeName);
                if (type != null)
                {
                    s_CachedTypes.Add(typeName, type);
                    return type;
                }

                foreach (System.Reflection.Assembly assembly in s_Assemblies)
                {
                    type = Type.GetType(Text.Format("{0}, {1}", typeName, assembly.FullName));

View on GitHub (pinned to d0c010b051)