dotnet/wpf · error · ArgumentException
SR.ListView_MissingParameterlessConstructor
Error message
SR.ListView_MissingParameterlessConstructor
What it means
GridViewHeaderRowPresenter.BuildHeaderLinks creates a floating header by instantiating the same type as an existing column header via Activator.CreateInstance. If the custom header type has no parameterless constructor, MissingMethodException is caught and rethrown as an ArgumentException wrapping it. The template system requires header types it can construct without arguments.
Solutions
- Add a public parameterless constructor to the custom GridViewColumnHeader-derived type
- Use the standard GridViewColumnHeader instead of a derived type for columns that participate in reordering
- Provide a default value for constructor parameters so a parameterless overload exists
Example fix
// before
class MyHeader : GridViewColumnHeader { public MyHeader(string title) { Content = title; } }
// after
class MyHeader : GridViewColumnHeader { public MyHeader() {} public MyHeader(string title) { Content = title; } } Defensive patterns
Strategy: validation
Validate before calling
bool ok = headerType?.GetConstructor(Type.EmptyTypes) != null;
Type guard
bool HasParameterlessCtor(Type t) => t.GetConstructor(Type.EmptyTypes) != null;
Try / catch
try { BuildHeaderLinks(); } catch (ArgumentException ex) when (ex.InnerException is MissingMethodException) { /* fall back to default GridViewColumnHeader */ } Prevention
- Always give custom header types a public parameterless constructor
- Test column drag/reorder paths with custom headers
- Avoid constructors with required parameters on control subclasses
When it happens
Trigger: Using a GridViewColumnHeader subclass without a public parameterless constructor as a column header, while the control builds floating headers (drag/reorder of columns, OnPreApplyTemplate/OnColumnPropertyChanged paths).
Common situations: Custom header classes with only constructor overloads taking parameters; headers instantiated only in XAML with constructor arguments; refactoring a constructor to require parameters and breaking header link building.
Related errors
- SR.CollectionView_ViewTypeInsufficient
- ArgumentNullException
- ArgumentNullException(nameof(assemblyNames))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/7a19f698e1a47bd7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewHeaderRowPresenter.cs:1159
// Create the floating header
private void AddFloatingHeader(GridViewColumnHeader srcHeader)
{
GridViewColumnHeader header;
// #1426973: Because users may put subclassed header as the column header,
// we need to create the same type per source header as the floating one
// Get source header's type
Type headerType = (srcHeader != null ? srcHeader.GetType() : typeof(GridViewColumnHeader));
try
{
// Instantiate the same type for floating header
header = Activator.CreateInstance(headerType) as GridViewColumnHeader;
}
catch (MissingMethodException e)
{
throw new ArgumentException(SR.Format(SR.ListView_MissingParameterlessConstructor, headerType), e);
}
Debug.Assert(header != null, "Cannot instantiate GridViewColumnHeader in AddFloatingHeader");
header.IsInternalGenerated = true;
header.SetValue(GridViewColumnHeader.RolePropertyKey, GridViewColumnHeaderRole.Floating);
header.Visibility = Visibility.Hidden;
InternalChildren.AddInternal(header);
_floatingHeader = header;
}
// Fill necessary properties in floating header
private void UpdateFloatingHeader(GridViewColumnHeader srcHeader)
{
Debug.Assert(srcHeader != null, "srcHeader is null");
Debug.Assert(_floatingHeader != null, "floating header is null");
View on GitHub (pinned to 81131a70a4)