lepoco/wpfui · critical · InvalidOperationException

The `UpdateActualWidth` method was not found.

Error message

The `UpdateActualWidth` method was not found.

What it means

Thrown lazily on first access of UpdateActualWidthMethod when reflection over System.Windows.Controls.GridViewColumn cannot find the private instance method 'UpdateActualWidth'. Companion to the _desiredWidth field guard (error 24); both are required for the column-width clamping feature. A failure means the WPF runtime changed its internals and the feature is incompatible with the loaded runtime.

Source

Thrown at src/Wpf.Ui/Controls/GridView/GridViewColumn.cs:48

{
    // use reflection to get the `_desiredWidth` private field.
    private static readonly Lazy<FieldInfo> _desiredWidthField = new(() =>
        typeof(System.Windows.Controls.GridViewColumn).GetField(
            "_desiredWidth",
            BindingFlags.NonPublic | BindingFlags.Instance
        ) ?? throw new InvalidOperationException("The `_desiredWidth` field was not found.")
    );

    private static FieldInfo DesiredWidthField => _desiredWidthField.Value;

    // use reflection to get the `UpdateActualWidth` private method.
    private static readonly Lazy<MethodInfo> _updateActualWidthMethod = new(() =>
    {
        MethodInfo methodInfo =
            typeof(System.Windows.Controls.GridViewColumn).GetMethod(
                "UpdateActualWidth",
                BindingFlags.NonPublic | BindingFlags.Instance
            ) ?? throw new InvalidOperationException("The `UpdateActualWidth` method was not found.");
        return methodInfo;
    });

    private static MethodInfo UpdateActualWidthMethod => _updateActualWidthMethod.Value;

    /// <summary>
    /// Updates the desired width of the column to be clamped between MinWidth and MaxWidth).
    /// </summary>
    /// <remarks>
    /// Uses reflection to directly set the private `_desiredWidth` field on the `System.Windows.Controls.GridViewColumn`.
    /// </remarks>
    /// <exception cref="InvalidOperationException">
    /// Thrown if reflection fails to access the `_desiredWidth` field
    /// </exception>
    internal void UpdateDesiredWidth()
    {
        double currentWidth = (double)(
            DesiredWidthField.GetValue(this)

View on GitHub (pinned to ffebacd610)

Solutions

  1. Target a .NET / WPF version whose GridViewColumn exposes 'UpdateActualWidth'.
  2. Avoid the ui:GridViewColumn MinWidth/MaxWidth feature until the library supports your runtime.
  3. Ensure reflection metadata is not trimmed (do not publish ready-to-run / AOT for this assembly).
  4. File an upstream issue with the runtime version so the method lookup can be patched.
Defensive patterns

Strategy: try-catch

Try / catch

try { col.UpdateDesiredWidth(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("UpdateActualWidth"))
{
    Logger.Warn($"Runtime missing UpdateActualWidth: {ex.Message}");
    // disable MinWidth/MaxWidth clamping
}

Prevention

When it happens

Trigger: First invocation of UpdateDesiredWidth on a .NET / WPF build where 'UpdateActualWidth' was renamed or removed; running under trimming/AOT that stripped the method metadata.

Common situations: Framework upgrade that refactored GridViewColumn; AOT-published WPF app; preview runtime where internal APIs shifted.

Related errors


AI-assisted analysis of lepoco/wpfui@ffebacd610 (2026-08-13). Data as JSON: /api/errors/c813c8558b92b4a2. Report an issue: GitHub.