c# - SetValue on Propertyinfo Target Exception object doesn't match target type error -


i'm trying set value property i'm getting "target exception object doesn't match target type error time".

the properties class

class wizardproperties {     public int incincidenttype { get; set; } } 

code snippet try set property value

 public void _wizardcontrol_nextbuttonclick(object sender, wizardcommandbuttonclickeventargs e)     {         foreach (control c in e.page.controls)         {             wizardproperties props = new wizardproperties();             searchlookupedit slue = new searchlookupedit();                foreach (var property in props.gettype().getproperties())                {                    if (!(c label))                    {                        if (property.name == c.name)                        {                            messagebox.show("matchhh!!");                             if (c searchlookupedit)                            {                               slue = (searchlookupedit)c;                            }                            propertyinfo info = props.gettype().getproperty(property.name);                             int type = convert.toint32(slue.editvalue);                             info.setvalue(property,type,null);                         }                    }                }          }      } 

the properties declared in separate class, error occurs at: info.setvalue(property,type,null). added null third parameter (solution found while searching error) didn't work me. type variable has valid int. how fix setvalue line?

edit: changed

 info.setvalue(property,type,null); 

to

 info.setvalue(props,type,null); 

fixed error

looks trying set value of property on propertyinfo object represent property want set rather on props instance of class. retrieving propertyinfo second time while looping through properties of props have removed that. assuming going props once code work. try below.:

foreach (control c in e.page.controls) {     wizardproperties props = new wizardproperties();     searchlookupedit slue = new searchlookupedit();     foreach (var property in props.gettype().getproperties())     {         if (!(c label) && property.name == c.name)         {              messagebox.show("matchhh!!");               if (c searchlookupedit)              {                  slue = (searchlookupedit)c;              }               int type = convert.toint32(slue.editvalue);               property.setvalue(props,type,null);          }      }  } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -