{"record":{"id":"a7f4983ff0ac3a5b","repo":"lepoco/wpfui","slug":"the-desiredwidth-field-was-not-found","errorCode":null,"errorMessage":"The `_desiredWidth` field was not found.","messagePattern":"The `_desiredWidth` field was not found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Wpf.Ui/Controls/GridView/GridViewColumn.cs","lineNumber":36,"sourceCode":"///         &lt;ui:GridView&gt;\n///             &lt;ui:GridViewColumn\n///                 MinWidth=\"100\"\n///                 MaxWidth=\"200\"\n///                 DisplayMemberBinding=\"{Binding FirstName}\"\n///                 Header=\"First Name\" /&gt;\n///         &lt;/ui:GridView&gt;\n///     &lt;/ui:ListView.View&gt;\n/// &lt;/ui:ListView&gt;\n/// </code>\n/// </example>\npublic class GridViewColumn : System.Windows.Controls.GridViewColumn\n{\n    // use reflection to get the `_desiredWidth` private field.\n    private static readonly Lazy<FieldInfo> _desiredWidthField = new(() =>\n        typeof(System.Windows.Controls.GridViewColumn).GetField(\n            \"_desiredWidth\",\n            BindingFlags.NonPublic | BindingFlags.Instance\n        ) ?? throw new InvalidOperationException(\"The `_desiredWidth` field was not found.\")\n    );\n\n    private static FieldInfo DesiredWidthField => _desiredWidthField.Value;\n\n    // use reflection to get the `UpdateActualWidth` private method.\n    private static readonly Lazy<MethodInfo> _updateActualWidthMethod = new(() =>\n    {\n        MethodInfo methodInfo =\n            typeof(System.Windows.Controls.GridViewColumn).GetMethod(\n                \"UpdateActualWidth\",\n                BindingFlags.NonPublic | BindingFlags.Instance\n            ) ?? throw new InvalidOperationException(\"The `UpdateActualWidth` method was not found.\");\n        return methodInfo;\n    });\n\n    private static MethodInfo UpdateActualWidthMethod => _updateActualWidthMethod.Value;\n\n    /// <summary>","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/lepoco/wpfui/blob/ffebacd61058170cf63864b7d5aa730cffff848a/src/Wpf.Ui/Controls/GridView/GridViewColumn.cs#L18-L54","documentation":"Thrown lazily (on first access of DesiredWidthField) when reflection over the base System.Windows.Controls.GridViewColumn fails to locate the private instance field '_desiredWidth'. WPF UI's GridViewColumn extension clamps column width via this field; if the .NET / WPF runtime renames or removes it, the feature cannot function and the library fails fast. This is a version-compatibility break, not a usage error.","triggerScenarios":"Running the MinWidth/MaxWidth clamping feature (first call to UpdateDesiredWidth) on a .NET / WPF build where the internal field '_desiredWidth' has been renamed or removed; targeting a future .NET version that refactored GridViewColumn internals.","commonSituations":"Upgrading the .NET target framework (e.g. to a preview or post-.NET-8 build) where WPF internals changed; running on a trimmed/AOT-compiled binary where reflection metadata for private members was stripped; using a custom WPF fork.","solutions":["Pin to a .NET / WPF version known to ship the '_desiredWidth' field (check the release the library targets).","Avoid triggering the clamp path: do not rely on ui:GridViewColumn MinWidth/MaxWidth and use the stock behavior instead.","If you control deployment, disable AOT/trimming for the WPF assembly so reflection metadata is preserved.","Report the break upstream so the field name / lookup can be updated for the new runtime."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { col.UpdateDesiredWidth(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"_desiredWidth\"))\n{\n    // Runtime incompatibility: fall back to stock GridViewColumn behavior\n    Logger.Warn($\"GridViewColumn reflection failed on this runtime: {ex.Message}\");\n}","preventionTips":["Pin to a .NET / WPF version the library officially supports.","Do not enable trimming/AOT for assemblies using this reflection-based feature.","Watch upstream release notes when upgrading the runtime."],"tags":["wpf","gridview","reflection","version-compatibility","internals"],"backgroundTag":null,"analyzedSha":"ffebacd61058170cf63864b7d5aa730cffff848a","analyzedAt":"2026-08-13T21:36:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}