Unity-Technologies/UnityCsReference · error · ArgumentNullException

type

Error message

type

What it means

AssetImporter.SourceAssetIdentifier(Type type, string name) constructor throws ArgumentNullException with param name 'type' when type is null. The constructor needs a valid System.Type to populate the identifier's type field. This is the type-name overload, distinct from the Object-based constructor (error 33).

Source

Thrown at Editor/Mono/AssetPipeline/AssetImporter.bindings.cs:42

    {
        public struct SourceAssetIdentifier
        {
            public SourceAssetIdentifier(Object asset)
            {
                if (asset == null)
                {
                    throw new ArgumentNullException("asset");
                }

                this.type = asset.GetType();
                this.name = asset.name;
            }

            public SourceAssetIdentifier(Type type, string name)
            {
                if (type == null)
                {
                    throw new ArgumentNullException("type");
                }

                if (name == null)
                {
                    throw new ArgumentNullException("name");
                }

                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentException("The name is empty", "name");
                }

                this.type = type;
                this.name = name;
            }

            public Type type;
            public string name;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Null-check the Type: if (type != null) new SourceAssetIdentifier(type, name).
  2. Use assembly-qualified type names and Assembly.GetType fallback when Type.GetType returns null.
  3. Validate type resolution and log the unresolved type name for debugging.

Example fix

// before
var t = Type.GetType(serializedTypeName);
var id = new SourceAssetIdentifier(t, assetName);

// after
var t = Type.GetType(serializedTypeName);
if (t == null)
    t = AppDomain.CurrentDomain.GetAssemblies()
        .Select(a => a.GetType(serializedTypeName))
        .FirstOrDefault(x => x != null);
if (t != null)
    var id = new SourceAssetIdentifier(t, assetName);
Defensive patterns

Strategy: validation

Validate before calling

if (type != null)
    var id = new AssetImporter.SourceAssetIdentifier(type, name);
else
    Debug.LogWarning($"Cannot create SourceAssetIdentifier: type is null");

Type guard

static bool IsValidType(Type type) => type != null;

Try / catch

try { var id = new AssetImporter.SourceAssetIdentifier(type, name); }
catch (ArgumentNullException ex) when (ex.ParamName == "type")
{ Debug.LogWarning($"Skipped SourceAssetIdentifier: {ex.Message}"); }

Prevention

When it happens

Trigger: Constructing new SourceAssetIdentifier(null, name) where the Type argument is null. This happens when type resolution fails (e.g., Type.GetType returns null for a type not in the executing assembly), or when a serialized type name cannot be resolved back to a Type object.

Common situations: Remap utilities that deserialize type names from external data (JSON, XML) and resolve them via Type.GetType, which returns null for types not in the calling assembly or mscorlib. Also occurs after assembly reorganization where type full names change.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/b58828029442b255. Report an issue: GitHub.