V3049. WPF: readonly field of 'DependencyProperty' type is not initialized.


The analyzer detected a possible error related to dependency property registration. A dependency property was defined but wasn't initialized: it will cause an error when trying to access the property using SetValue / GetValue.

class A : DependencyObject
{
  public static readonly DependencyProperty CurrentTimeProperty;
  static A(){ /* CurrentTimeProperty not initialized */ }
      ....

Bad refactoring or copy-paste may result in leaving a dependency property unregistered. The following is the fixed version of the code above:

class A : DependencyObject
{
public static readonly DependencyProperty CurrentTimeProperty;
static A()
{
  CurrentTimeProperty =
    DependencyProperty.Register("CurrentTime", typeof(DateTime),
                                typeof(A));
}
....

Bugs Found

Checked Projects
344
Collected Errors
12 899