views:

237

answers:

2

i have such code

Bitmap b = new Bitmap(@"d:\0.bmp");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.DoOCR(b, Rectangle.Empty);

the i try to make it through reflection

Assembly a = Assembly.Load("tessnet2_32");
Type myType = a.GetType("tessnet2.Tesseract");
MethodInfo mymethod = myType.GetMethod("DoOCR");
Object obj = Activator.CreateInstance(myType);
mymethod.Invoke(obj, null);

how can i pass parameters?

+1  A: 

that would be through the MethodInfo.Invoke(obj, object[] parameters) method

so myMethod.Invoke(obj, new object[] {b, Rectangle.Empty});

Hath
+3  A: 
mymethod.Invoke(obj, new object[] { b, Rectangle.Empty });
actual
hmmnow i have exceprion Exception has been thrown by the target of an invocationcan you explaine why? method is working well if a call it without reflection
kusanagi
Maybe DoOCR is overloaded, try to get more specific method with: myType.GetMethod("DoOCR", new Type[] { typeof(Bitmap), typeof(Rectangle) });
actual
Sorry, that idea with overloading is wrong, in this case exception should be thrown on GetMethod line.
actual
Check the innerException of the thrown exception to see whats going on
codymanix
Also make sure that b is not null before passing it
codymanix