Skip to content

[bug]Silent propertyChangedCallback: null generation when using WPF standard DependencyPropertyChangedEventArgs signature in OnChanged #165

Open

Description

@kassyi

Describe the bug

When using the [AttachedDependencyProperty] (or [DependencyProperty]) attribute and specifying the OnChanged parameter, the generator silently outputs propertyChangedCallback: null if the specified method uses the standard WPF DependencyPropertyChangedEventArgs signature.

There are no compiler errors or Roslyn warnings, causing the property changed event to silently fail at runtime. Developers can spend hours debugging why their attached properties are not firing, only to discover the generated code hardcoded a null callback.

Steps to reproduce the bug

  1. Define an attached property and specify the OnChanged callback.
  2. Define the callback method using the standard WPF signature (DependencyObject, DependencyPropertyChangedEventArgs).
using System.Windows;
using DependencyPropertyGenerator;

namespace Repro;

[AttachedDependencyProperty<string>("Test", OnChanged = nameof(OnTestChanged))]
public static partial class TestHelper
{
    // Standard WPF signature
    private static void OnTestChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        // This will NEVER be called.
    }
}

Expected behavior

Actual Behavior (Generated Code)

The generator fails to parse or match the signature and outputs propertyChangedCallback: null without any warnings.

public static readonly global::System.Windows.DependencyProperty TestProperty =
    global::System.Windows.DependencyProperty.RegisterAttached(
        name: "Test",
        propertyType: typeof(string),
        ownerType: typeof(global::Repro.TestHelper),
        defaultMetadata: new global::System.Windows.FrameworkPropertyMetadata(
            defaultValue: default(string),
            flags: global::System.Windows.FrameworkPropertyMetadataOptions.None,
            propertyChangedCallback: null, // 🚨 Silently set to null
            coerceValueCallback: null,
            isAnimationProhibited: false),
        validateValueCallback: null);

Screenshots

No response

NuGet package version

Environment

  • Framework: .NET 8.0 / .NET 10.0 (WPF)
  • Package: DependencyPropertyGenerator v1.5.1
  • Language: C# 12+

IDE

No response

Additional context

The generator should ideally support the standard WPF signature. However, if that signature is explicitly unsupported, the generator must emit a Roslyn Diagnostic Error/Warning (e.g., DPG0001: The signature of the specified OnChanged method is unsupported.) so developers are immediately aware of the issue at compile time.

Proposed Solutions

  1. Immediate Mitigation (Analyzer Warning):
    Add a diagnostic analyzer rule that triggers an Error or Warning when OnChanged is specified but no compatible method signature can be found/matched in the target class.
  2. Feature Enhancement:
    Support parsing and wiring up methods that accept (DependencyObject d, DependencyPropertyChangedEventArgs e), as this is the universally recognized signature in WPF/UWP/WinUI development.

Activity

  1. kassyi commented on Jul 24, 2026

    @kassyi
    Author

    I fixed this bug in the following repository: https://github.com/kassyi/DependencyPropertyGenerator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions