{"record":{"id":"a87515cc2b8d4e86","repo":"Unity-Technologies/UnityCsReference","slug":"type-a87515","errorCode":null,"errorMessage":"type","messagePattern":"type","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/SpeedTree/SpeedTreeImporterSettings.cs","lineNumber":154,"sourceCode":"        public string type;\n        public string name;\n\n        public AssetIdentifier(UnityEngine.Object asset)\n        {\n            if (asset == null)\n            {\n                throw new ArgumentNullException(\"asset\");\n            }\n\n            this.type = asset.GetType().ToString();\n            this.name = asset.name;\n        }\n\n        public AssetIdentifier(Type type, string name)\n        {\n            if (type == null)\n            {\n                throw new ArgumentNullException(\"type\");\n            }\n\n            if (name == null)\n            {\n                throw new ArgumentNullException(\"name\");\n            }\n\n            if (string.IsNullOrEmpty(name))\n            {\n                throw new ArgumentException(\"The name is empty\", \"name\");\n            }\n\n            this.type = type.ToString();\n            this.name = name;\n        }\n    }\n\n    /// <summary>","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/SpeedTree/SpeedTreeImporterSettings.cs#L136-L172","documentation":"AssetIdentifier pairs a System.Type with a name to identify a source asset inside the SpeedTree importer pipeline. The AssetIdentifier(Type, string) constructor guards its first argument: a null Type is rejected with ArgumentNullException because the identifier stores type.ToString() and a null Type would otherwise surface as a NullReferenceException much later during serialization/remapping. The check keeps the failure local and the message specific.","triggerScenarios":"Calling new AssetIdentifier(null, someName); passing a Type obtained via Type.GetType(typeName) or assembly.GetType(typeName) where the lookup silently returned null; building identifiers from deserialized config whose type field failed to resolve.","commonSituations":"Type-load-by-name that fails after a rename or after moving a class between assemblies; config/asset references that name a type no longer present after a Unity upgrade; unit tests scaffolding identifiers with a placeholder null.","solutions":["Resolve the Type before constructing and validate it is non-null (e.g. var t = Type.GetType(typeName); if (t == null) throw new InvalidOperationException(\"Unknown type \" + typeName);).","If the type came from reflection, prefer typeof(KnownType) or a known assembly-qualified name so the lookup cannot silently fail.","Catch the failure at the boundary (config load) and report the offending type name rather than letting it reach the constructor."],"exampleFix":"// before\nvar id = new AssetIdentifier(Type.GetType(cfg.typeName), cfg.name);\n\n// after\nvar t = Type.GetType(cfg.typeName);\nif (t == null)\n    throw new InvalidOperationException(\"Unknown type: \" + cfg.typeName);\nvar id = new AssetIdentifier(t, cfg.name);","handlingStrategy":"validation","validationCode":"Type ResolveType(string typeName) {\n    var t = Type.GetType(typeName);\n    if (t == null)\n        throw new InvalidOperationException(\"Unknown type: \" + typeName);\n    return t;\n}\n// then: new AssetIdentifier(ResolveType(cfg.typeName), cfg.name);","typeGuard":"static bool IsValidIdentifierType(Type t) => t != null;","tryCatchPattern":null,"preventionTips":["Prefer typeof(T) over Type.GetType(string) so unresolved types fail at compile time.","When loading types by name, always null-check the result and report the name.","Keep type names in config assembly-qualified to survive renames and moves."],"tags":["unity","speedtree","argument-validation","null-check","asset-pipeline"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}