Error on using Fody [ImplementPropertyChanged]

A.Hussainy picture A.Hussainy · Jun 10, 2017 · Viewed 7.7k times · Source

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

Answer

woelliJ picture woelliJ · Jun 10, 2017

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)