Error on using Fody [ImplementPropertyChanged]
Asked Answered
T

2

6

I am Using VS 2017 Community Edition I am creating MVVM pattern. After i installed fody i got error on my code while the instructor of the tutorial implemented it on vs 2015 here is the code:

using PropertyChanged;
using System.ComponentModel;

namespace GProject_MVVM.ViewModel
{
    /// <summary>
    /// A base view model that fires Property Changed events as needed
    /// </summary>
    [ImplementPropertyChanged] // **I got error here**
    public class BaseViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// The event that is fired when any child property changes its value
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
        /// <summary>
        /// Call this to fire <see cref="PropertyChanged"/> event
        /// </summary>
        /// <param name="name"></param>
        public void OnPropertyChanged(string name)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));

        }
    }
}

[ImplementPropertyChanged] should not make error on this point the instructor implemented it successfully so is thier anything missing on my code ? The error says:

Severity Code Description Project File Line Suppression State Error CS0619 'ImplementPropertyChangedAttribute' is obsolete: 'This configuration option has been deprecated. The use of this attribute was to add INotifyPropertyChanged to a class with its associated event definition. After that all classes that implement INotifyPropertyChanged have their properties weaved, weather they have the ImplementPropertyChangedAttribute or not. This attribute was often incorrectly interpreted as an opt in approach to having properties weaved, which was never the intent nor how it ever operated. This attribute has been replaced by AddINotifyPropertyChangedInterfaceAttribute.' GProject_MVVM c:\users\ahmed hussainy\documents\visual studio 2017\Projects\GProject_MVVM\GProject_MVVM\ViewModel\BaseViewModel.cs 9 Active

Trenna answered 10/6, 2017 at 6:30 Comment(0)
T
19

The exception already states the answer.

ImplementPropertyChangedAttribute' is obsolete: 'This configuration option has been deprecated. The use of this attribute was to add INotifyPropertyChanged to a class with its associated event definition. After that all classes that implement INotifyPropertyChanged have their properties weaved, weather they have the ImplementPropertyChangedAttribute or not.

With the new version of Fody.PropertyChanged you don't need to add the attribute any longer. Just make that class you want to be weaved implement INotifyPropertyChanged and it will work.

So basically just remove / delete [ImplementPropertyChanged] and it will compile and weave (if the weaver is present in FodyWeavers.xml)

Tabular answered 10/6, 2017 at 6:36 Comment(0)
R
1

If you originally used this attribute exactly the way it was meant to be used, you should replace it with [AddINotifyPropertyChangedInterface].

This way Fody will add the INotifyPropertyChanged interface to your class, and then the weaver will implement it properly.

Release answered 24/4, 2021 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.