![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi All, I have this following code which works fine in 1.1 but gives runtime exception 2.0:- Reflection Code to get One Property from COM Object ------------------------------------------------------------------------------- Dim objSession as Interop.ComObj.Session Dim objAgent as Interop.ComObj.Agent Dim objAgentType as Type Dim PropertyName as String Dim itemProperty as PropertyInfo Dim propertyValue as Object objAgent = objSession.Create("Agent") objAgentType = GetType(Interop.ComObj.AgentClass) ' Important to use Class and not Interface. If you use Interface the reflection does not find the property. itemProperty = objAgentType.GetProperty(PropertyName) ' make sure the Propertyname exactly matches the property of COM object( including case) 'Get Property Value propertyValue = itemProperty.GetValue(objAgent, Nothing) If Not (propertyValue Is Nothing) Then ItemValue = propertyValue.ToString() Else ItemValue = String.Empty End If 'Set Property Value Dim NewValue as String = "TestValue" itemProperty.SetValue(objCustomer, System.Convert.ChangeType(NewValue, itemProperty.PropertyType), Nothing) ' This line gives error. The COM Property is String type The error is given below:- Error Description: Object does not match target type. Source: mscorlib Stack Trace: at System.Reflection.RuntimeMethodInfo.CheckConsisten cy(Object target) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.SetValue(Obj ect obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at CMBrowser.OnBoardCustomer.SetPropertyValueEx(Type& objType, String ColumnName, String ItemValue, Object& objCom) in C:\SRCREF\CMBrowser\OnBoardCustomer.aspx.vb:line 4314 Class: RuntimeMethodInfo Proc Name: CheckConsistency Any clues as to why this is happening? This exception occurs for all properties irrespective of their types. Piyush |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |