using System;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Linq.Expressions;

namespace ConsoleApplication
{
    class MyViewModel : INotifyPropertyChanged
    {
        public object Value { get; set; }
        public event PropertyChangedEventHandler PropertyChanged;
    }

    public class Program
    {
        public static void Main()
        {
            var OnValueChanged = new Action<MyViewModel>(x => { });
            var myObserver = new PropertyObserver<MyViewModel>();
            //this line throws the error, within the n => n.Value expression
            myObserver.RegisterHandler(n => n.Value, OnValueChanged);
        }
    }

    public class PropertyObserver<TPropertySource> where TPropertySource : INotifyPropertyChanged
    {
        public PropertyObserver<TPropertySource> RegisterHandler(Expression<Func<TPropertySource, object>> expression, Action<TPropertySource> handler)
        {
            Contract.Requires(expression != null);
            Contract.Requires(handler != null);

            throw new NotImplementedException();
            //what this does is irrelevant; the violation  occurs in the method call
        }
    }
}