Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There is a third party assembly which I would like to call dynamically.

Meaning I need to call a method of a class only when that third party assembly is present. (The application is deployed as a click-once deployment)

Thanks
/Amaw Scritz
Posted
Comments
Sushil Mate 31-Oct-12 0:01am    
whats stopping you?
Sergey Alexandrovich Kryukov 31-Oct-12 0:25am    
It's not a problem, but better to support some interface (otherwise you will have to find type/method by name, which is always bad for support and debugging). What did you try? This is straightforward: read on Reflection APIs and act "by definition", nothing tricky.
--SA

1 solution

You can try something like:
C#
var t = Type.GetType("the full name of your class here");

if (t != null)
{
     // the type is present so your assembly is there
     var methodToCall = t.GetMethod("Name of the method to call");
     // invocation
     var result = methodToCall.Invoke(<targetornullifstaticmethod>, <parametersasanarrayofobjects>);

}

targetOrNullIfStaticMethod being the object instance on which you want to call the method
parametersAsAnArrayOfObjects being an array of the parameters the method is expecting (or null if no parameters)
 
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