{"record":{"id":"7a19f698e1a47bd7","repo":"dotnet/wpf","slug":"sr-listview-missingparameterlessconstructor","errorCode":null,"errorMessage":"SR.ListView_MissingParameterlessConstructor","messagePattern":"SR\\.ListView_MissingParameterlessConstructor","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewHeaderRowPresenter.cs","lineNumber":1159,"sourceCode":"\n        // Create the floating header\n        private void AddFloatingHeader(GridViewColumnHeader srcHeader)\n        {\n            GridViewColumnHeader header;\n\n            // #1426973: Because users may put subclassed header as the column header,\n            //           we need to create the same type per source header as the floating one\n            // Get source header's type\n            Type headerType = (srcHeader != null ? srcHeader.GetType() : typeof(GridViewColumnHeader));\n\n            try\n            {\n                // Instantiate the same type for floating header\n                header = Activator.CreateInstance(headerType) as GridViewColumnHeader;\n            }\n            catch (MissingMethodException e)\n            {\n                throw new ArgumentException(SR.Format(SR.ListView_MissingParameterlessConstructor, headerType), e);\n            }\n\n            Debug.Assert(header != null, \"Cannot instantiate GridViewColumnHeader in AddFloatingHeader\");\n\n            header.IsInternalGenerated = true;\n            header.SetValue(GridViewColumnHeader.RolePropertyKey, GridViewColumnHeaderRole.Floating);\n            header.Visibility = Visibility.Hidden;\n\n            InternalChildren.AddInternal(header);\n            _floatingHeader = header;\n        }\n\n        // Fill necessary properties in floating header\n        private void UpdateFloatingHeader(GridViewColumnHeader srcHeader)\n        {\n            Debug.Assert(srcHeader != null, \"srcHeader is null\");\n            Debug.Assert(_floatingHeader != null, \"floating header is null\");\n","sourceCodeStart":1141,"sourceCodeEnd":1177,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewHeaderRowPresenter.cs#L1141-L1177","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nclass MyHeader : GridViewColumnHeader { public MyHeader(string title) { Content = title; } }\n// after\nclass MyHeader : GridViewColumnHeader { public MyHeader() {} public MyHeader(string title) { Content = title; } }","handlingStrategy":"validation","validationCode":"bool ok = headerType?.GetConstructor(Type.EmptyTypes) != null;","typeGuard":"bool HasParameterlessCtor(Type t) => t.GetConstructor(Type.EmptyTypes) != null;","tryCatchPattern":"try { BuildHeaderLinks(); } catch (ArgumentException ex) when (ex.InnerException is MissingMethodException) { /* fall back to default GridViewColumnHeader */ }","preventionTips":["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"],"tags":["wpf","gridview","reflection","constructor"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}