Click here to Skip to main content
16,013,642 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello All,

How can I detect if the _Object has null value used in reflection?

code:
orgfldInfo[i].GetValue(_Object, null)


When I am using above code it gives me error:
"Error from target invocation"


Stack trace exception


C++
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   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.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at InSync.BillingBL.CPayments.BillingLog(Object _OldValue, Object _NewValue, String PageName, String Event) in D:\InSync5.4\CareEMRBillingBL\CPayments.cs:line 168
Posted
Updated 17-Nov-10 23:43pm
v4

1 solution

I'd place a bet that the error message is not "Error from target invocation" as you stated. It's probably more along the lines of "Exception has been thrown by the target of an invocation.". Anywho, please give the complete error message in addition to all exception information (including the stacktrace).

Using the debugger you should place a breakpoint on that line and check all variables for unusual values.

Modification:
or did you mean something like this:

if(_Object!=null)
{
    orgfldInfo[i].GetValue(_Object, null)
}
else
{
    //Do something else
}


End Modification


Cheers

Manfred
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900