{"record":{"id":"ca0e1c862cebf68b","repo":"dotnet/machinelearning","slug":"rawtype","errorCode":null,"errorMessage":"rawType","messagePattern":"rawType","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewType.cs","lineNumber":26,"sourceCode":"using System.Threading;\n\nnamespace Microsoft.ML.Data\n{\n    /// <summary>\n    /// This is the abstract base class for all types in the <see cref=\"IDataView\"/> type system.\n    /// </summary>\n    /// <remarks>\n    /// Those that wish to extend the <see cref=\"IDataView\"/> type system should derive from one of\n    /// the more specific abstract classes <see cref=\"StructuredDataViewType\"/> or <see cref=\"PrimitiveDataViewType\"/>.\n    /// </remarks>\n    public abstract class DataViewType : IEquatable<DataViewType>\n    {\n        /// <summary>\n        /// Constructor for extension types, which must be either <see cref=\"PrimitiveDataViewType\"/> or <see cref=\"StructuredDataViewType\"/>.\n        /// </summary>\n        private protected DataViewType(Type rawType)\n        {\n            RawType = rawType ?? throw new ArgumentNullException(nameof(rawType));\n        }\n\n        /// <summary>\n        /// The raw <see cref=\"Type\"/> for this <see cref=\"DataViewType\"/>. Note that this is the raw representation type\n        /// and not the complete information content of the <see cref=\"DataViewType\"/>.\n        /// </summary>\n        /// <remarks>\n        /// Code should not assume that a <see cref=\"RawType\"/> uniquely identifiers a <see cref=\"DataViewType\"/>.\n        /// For example, most practical instances of ML.NET's KeyType and <see cref=\"NumberDataViewType.UInt32\"/> will have a\n        /// <see cref=\"RawType\"/> of <see cref=\"uint\"/>, but both are very different in the types of information conveyed in that number.\n        /// </remarks>\n        public Type RawType { get; }\n\n        // IEquatable<T> interface recommends also to override base class implementations of\n        // Object.Equals(Object) and GetHashCode. In classes below where Equals(ColumnType other)\n        // is effectively a referencial comparison, there is no need to override base class implementations\n        // of Object.Equals(Object) (and GetHashCode) since its also a referencial comparison.\n        /// <summary>","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewType.cs#L8-L44","documentation":"The internal DataViewType constructor throws ArgumentNullException(\"rawType\") when a derived extension type passes null for its raw representation Type. RawType is the CLR type backing the DataViewType (used by AddPrimitiveValue and getters), so it is mandatory for every DataViewType instance.","triggerScenarios":"Implementing a custom DataViewType subclass whose base(...) call forwards a null Type, e.g. passing a Type resolved from reflection (assembly.GetType) that returned null, or a nullable field not yet initialized.","commonSituations":"Custom data view type extension development; resolving types by string name from config where the name didn't match; base-class constructor ordering that forwards an uninitialized static Type field.","solutions":["Pass a concrete CLR Type to the base constructor: base(typeof(MyRepresentation)).","Verify reflection-based Type lookups succeeded before constructing the DataViewType.","Initialize backing Type fields statically (e.g. private static readonly Type Raw = typeof(X))."],"exampleFix":"// before\npublic MyType() : base(GetRawType()) { } // GetRawType() can return null\n// after\npublic MyType() : base(typeof(float)) { }","handlingStrategy":"validation","validationCode":"if (rawType == null) throw new ArgumentException(\"Custom DataViewType requires a non-null CLR representation type\");","typeGuard":"bool HasRawType(Type t) => t != null;","tryCatchPattern":"try { new MyCustomType(); } catch (ArgumentNullException ex) when (ex.ParamName == \"rawType\") { /* fix base() call */ }","preventionTips":["Pass typeof(...) literals to the base constructor when possible","Check reflection Type resolution results before constructing","Initialize representation Types as static readonly fields"],"tags":["csharp","null-argument","custom-type","ml-net"],"backgroundTag":"null-argument","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}