Link to home
Start Free TrialLog in
Avatar of Skale
Skale

asked on

How to solve TargetInvocationException issue in C#

Hello,

I'd like access one of the parameter from my COM interface class with below code;

simpackcomslvLib.ScrTypeVarParameter par = prim.par(index[0], index[1], index[2], index[3], index[4], index[5], index[6], index[7], index[8]);
Console.WriteLine(par.val);

Open in new window



if it's existing with that indexes it gives result but if there's no parameter at given indexes it throws TargetInvocationException. I'd like to avoid that throw but didn't succeeded it. I tried to check if par == null but it's always not null it always shows System.__ComObject and if i tried to check par.val it throws that TargetInvocationException, so how can i avoid if parameter doesnt exists at given index i'd like to pass and try new indexes but as i said it throws an error.
Avatar of ste5an
ste5an
Flag of Germany image

Seems like you mean Type.Missing. For each unspecified parameter, e.g.

simpackcomslvLib.ScrTypeVarParameter par = prim.par(index[0], Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

Open in new window

Avatar of Skale
Skale

ASKER

I dont understand clearly ste5an what you mean but it couldn't access the parameter becaues it's not exist.

Well, maybe you should rephrase your question. Cause it is pretty vague.

I'd like access one of the parameter from my COM interface class with below code [..]
 if it's existing with that indexes it gives result but if there's no parameter at given indexes it throws TargetInvocationException.
What does access a parameter mean?
Where's the code of the class and the relevant methods?
What does "existing with that indexes" mean?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial