Using NUnit + Reflection cannot find any events in my ActiveX control

I am testing an old-school COM / ActiveX control using NUnit and C #. I do everything dynamically, no links or information like compile time, because the control that I am testing is used mainly from javascript - which, of course, does everything dynamically. I want to hook some event handlers and make sure the events are fired properly, but I cannot find the events! I am dynamically creating an instance of the control using System.Activator.CreateInstance, for example (some details are omitted ;-):

Type T = Type.GetTypeFromCLSID(guid); eztwain = System.Activator.CreateInstance(T); EZTwainX = eztwain.GetType(); 

Tests of properties and methods work fine, for example:

 EZTwainX.InvokeMember("Clear", BindingFlags.InvokeMethod, null, eztwain, null); Assert.AreEqual(0, (int)EZTwainX.InvokeMember("ImageCount", BindingFlags.GetProperty, null, eztwain, null), "ImageCount"); 

The following errors fail by returning a null or empty array or throwing a "name not found" exception:

 EZTwainX.GetEvent("AcquireDone"); // returns null EZTwainX.GetEvents(); // returns empty array EZTwainX.GetEvents(BindingFlags.Public | // returns empty array BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); PropertyInfo propertyInfo = EZTwainX.GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); // returns null MemberInfo[] mimfo = EZTwainX.GetMember("AcquireDone", MemberTypes.Event, BindingFlags.Public | BindingFlags.NonPublic); // returns empty array 

I just assumed (um) that I could do something using the Reflection API equivalent:

 eztwain.AcquireDone += <event handler>; 

but I can’t understand what it is. EDIT: I believe in this event on this control, because in Javascript this works (and catches events):

 eztwain.attachEvent("AcquireDone", function() { me.onAcquireDone(); }); 
+4
source share
1 answer

See How to deal with events raised using a COM source

Also pay attention to a utility that you can use ( Ildasm.exe (IL Disassembler) ) to get event signatures.

0
source

Source: https://habr.com/ru/post/1393027/


All Articles