Export to GitHub

fast-member - issue #2

TypeAccessor.WriteSetter throws exception, if property setter is not public


Posted on Jan 27, 2012 by Massive Cat

The method TypeAccessor.WriteSetter throws an ArgumentNullException, if the target type has a property with a non-public setter. (Line 141: http://code.google.com/p/fast-member/source/browse/FastMember/TypeAccessor.cs#141)

Example: class TestTarget { public int Id { get; private set; } }

I am not sure why prop.GetSetMethod() returns null, although prop.CanWrite obviously returned true in line 129.

Comment #1

Posted on Feb 5, 2012 by Happy Monkey

Not sure if this is the best (fastest) way, but adding this at line 130 fixes this:

var setMethod = prop.GetSetMethod(); if (setMethod == null || !setMethod.IsPublic) continue;

http://code.google.com/p/fast-member/source/browse/FastMember/TypeAccessor.cs#130

Comment #2

Posted on Feb 28, 2012 by Swift Panda

Comment deleted

Comment #3

Posted on Feb 28, 2012 by Swift Panda

I think this line:

if (prop.GetIndexParameters().Length != 0 || !prop.CanWrite) continue;

should be:

if (prop.GetIndexParameters().Length != 0 || !prop.CanWrite || !prop.GetSetMethod().IsPublic) continue;

It seems the intention there is that CanWrite would return false if the property is not writeable, in fact all that CanWrite checks for is the existence of a set method, it does not however check the availability of that method.

Comment #4

Posted on Feb 28, 2012 by Swift Panda

I added a simple test that verifies this issue, and a fairly simple fix as well. I wasn't sure how to contribute (or if I could) code to this project, so I created a couple of diff files (using hg diff) and I've attached them here.

Attachments

Status: New

Labels:
Type-Defect Priority-Medium