Reputation: 29159
I have the following code. However, it has a runtime exception on SetValue
. What may cause the error?
var _filter = new Filter(....); // Filter implemented IFilter
ApplyFilter(_view.Name, x => x.Name);
private void ApplyFilter<T>(T curr, Expression<Func<IFilter, T>> prev)
{
var expr = (MemberExpression)prev.Body;
var prop = (PropertyInfo)expr.Member;
if (!EqualityComparer<T>.Default.Equals(curr, (T)_filter[prop.Name]))
{
prop.SetValue(_filter, curr, null); // Error
..... // do something on _filter
The exception is:
System.ArgumentException was unhandled Message=Property set method not found. Source=mscorlib StackTrace: at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) at MyApp.ErrorLogPresenter.ApplyFilter[T](T curr, Expression`1 prev) in d:\....cs:line 50
Upvotes: 0
Views: 1580
Reputation: 1062492
Message=Property set method not found.
This usually simply means that the property you are using does not define a setter. Either ensure that a suitable setter exists, or use a different approach to assign values.
Upvotes: 4