jeudi 3 mars 2016

Object does not match target type in c#

I have a class that contain this property.

public List<string> Messages { get; set; }

I want to read value of that property.

List<string> messages = new List<string>();
PropertyInfo prop = myType.GetProperty("Messages");
var message = prop.GetValue(messages);

but I get this error :

"Object does not match target type."

I used this line:

var message = prop.GetValue(messages,null);

instead of

var message = prop.GetValue(messages);

but still I get the same error.





Aucun commentaire:

Enregistrer un commentaire