I'm working with some code that's suddenly stopped functioning. I tracked the problem down to CallerMemberName feature in .NET 4
It seems that it just stopped working, [CallerMemberName] String propertyName = "" returns "", even though it's being called from the property "speed". It was working fine previously, and I checked that the project is targeting ".NET Framework 4". Any idea what could cause this?
Property code:
public double speed
{
get { return _speed; }
set
{
_speed = value;
NotifyPropertyChanged();
}
}
and it's processed here:
//events
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
void RealTimeDashboard_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "speed":
NotifyPropertyChanged("speedDescription");
CalculateEfficency();
CheckEfficentConfigurations();
break;
}
}
Edit: Installed The Microsoft BCL Portability Pack and it behaves the same but with the following warning:
Warning 10 The type 'System.Runtime.CompilerServices.CallerMemberNameAttribute' in 'D:\Projects...MainWindow.xaml.cs' conflicts with the imported type 'System.Runtime.CompilerServices.CallerMemberNameAttribute' in 'd:\Projects...\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Runtime.dll'. Using the type defined in 'D:\Projects....\MainWindow.xaml.cs'. D:\Projects...AnOtherClass.xaml.cs