"Object does not match target type" indicates that myObject
is not an instance of the type that propertyInfo
was obtained from. In other words, the property you are trying to set is on one type, and myObject
is not an instance of that type.
To illustrate:
var streamPosition = typeof(Stream).GetProperty("Position");
// "Object does not match target type," because the object we tried to
// set Position on is a String, not a Stream.
streamPosition.SetValue("foo", 42);