dotnet/machinelearning · error · ArgumentNullException
rawType
Error message
rawType
What it means
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.
Source
Thrown at src/Microsoft.ML.DataView/DataViewType.cs:26
using System.Threading;
namespace Microsoft.ML.Data
{
/// <summary>
/// This is the abstract base class for all types in the <see cref="IDataView"/> type system.
/// </summary>
/// <remarks>
/// Those that wish to extend the <see cref="IDataView"/> type system should derive from one of
/// the more specific abstract classes <see cref="StructuredDataViewType"/> or <see cref="PrimitiveDataViewType"/>.
/// </remarks>
public abstract class DataViewType : IEquatable<DataViewType>
{
/// <summary>
/// Constructor for extension types, which must be either <see cref="PrimitiveDataViewType"/> or <see cref="StructuredDataViewType"/>.
/// </summary>
private protected DataViewType(Type rawType)
{
RawType = rawType ?? throw new ArgumentNullException(nameof(rawType));
}
/// <summary>
/// The raw <see cref="Type"/> for this <see cref="DataViewType"/>. Note that this is the raw representation type
/// and not the complete information content of the <see cref="DataViewType"/>.
/// </summary>
/// <remarks>
/// Code should not assume that a <see cref="RawType"/> uniquely identifiers a <see cref="DataViewType"/>.
/// For example, most practical instances of ML.NET's KeyType and <see cref="NumberDataViewType.UInt32"/> will have a
/// <see cref="RawType"/> of <see cref="uint"/>, but both are very different in the types of information conveyed in that number.
/// </remarks>
public Type RawType { get; }
// IEquatable<T> interface recommends also to override base class implementations of
// Object.Equals(Object) and GetHashCode. In classes below where Equals(ColumnType other)
// is effectively a referencial comparison, there is no need to override base class implementations
// of Object.Equals(Object) (and GetHashCode) since its also a referencial comparison.
/// <summary>View on GitHub (pinned to 7b76e69cf9)
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)).
Example fix
// before
public MyType() : base(GetRawType()) { } // GetRawType() can return null
// after
public MyType() : base(typeof(float)) { } Defensive patterns
Strategy: validation
Validate before calling
if (rawType == null) throw new ArgumentException("Custom DataViewType requires a non-null CLR representation type"); Type guard
bool HasRawType(Type t) => t != null;
Try / catch
try { new MyCustomType(); } catch (ArgumentNullException ex) when (ex.ParamName == "rawType") { /* fix base() call */ } Prevention
- Pass typeof(...) literals to the base constructor when possible
- Check reflection Type resolution results before constructing
- Initialize representation Types as static readonly fields
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- columns
- A PrimitiveDataViewType cannot have a disposable RawType
- Value cannot be null. (Parameter 'input')
- getter must be of type '{typeof(ValueGetter<TValue>).FullNam
- throw new ArgumentNullException(nameof(ids));
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/ca0e1c862cebf68b.
Report an issue: GitHub.