target exception was unhandled in reflection

Posted by Santosh198318 under C# on 5/10/2012 | Points: 10 | Views : 1869 | Status : [Member] | Replies : 0
please help in this issue..






public void RetrievetypeofEntity()
{
Migratedata.CRM40.account ent = new CRM40.account();
Migratedata.CRM2011.account ent1 = new CRM2011.account()
var prpCRM40 = Type.GetType("Migratedata.CRM40.account");
Console.WriteLine(prpCRM40);
var prp2011 = Type.GetType("Migratedata.CRM2011.account");
Console.WriteLine(prp2011);
//Console.WriteLine(prp2);
PropertyInfo[] propertyInfos2011;
Console.WriteLine("CRM 2011 properties----");

PropertyInfo[] propertyInfo40 = prpCRM40.GetProperties();

propertyInfos2011 = prp2011.GetProperties();

int currentIndex = 0;
foreach (PropertyInfo propertyInfo in propertyInfos2011)
{
//if (propertyInfo.Name == "address1_line1")
//{
string correspondingPropNameIn40 = GetCRM40PropertyName(propertyInfo.Name);//here am getting the crm4.0 property name passing the 2011 property
//int? correspondingPropIndexIn40 = GetCRM40PropertyIndex(propertyInfo40, correspondingPropNameIn40);

if (correspondingPropNameIn40 != null)
{
int correspondingPropIndexIn40 = GetCRM40PropertyIndex(propertyInfo40, correspondingPropNameIn40);
if (correspondingPropIndexIn40 != 0)
{
//propertyInfo.SetValue(prp2011,propertyInfo40[correspondingPropIndexIn40].Name, null);
propertyInfo.SetValue(prp2011, propertyInfo40[correspondingPropIndexIn40].GetValue(prpCRM40,null), null);---------------------------->here am getting the object does not match target type




// propertyInfo.SetValue(prp2011, propertyInfo40[correspondingPropIndexIn40].GetValue(prpCRM40, null), null);
// propertyInfo.SetValue(prp2011, correspondingPropIndexIn40, null); //(object name of 2011, 4.0(GetValue(object name of 4.0), null), null)

}
Console.WriteLine(propertyInfo.Name);
//}
currentIndex = currentIndex + 1;
}
}
Console.ReadLine();



}


Object does not match target type in PropertyInfo-----> target exception was unhandled




Responses

(No response found.)

Login to post response