2

Let us consider im having an application named as AAA. Now Im Loading an assembly named as BBB.The aseembly BBB is having the declaration of event and delegate. The handler to the event in BBB is available in AAA. while loading the assembly BBB, i need to add the handler for the event in AAA. Whenever the event occurs in BBB, the handler method in AAA shoud gets executed automatically. How to accomplish this..........?

i coded like dis in AAA

Assembly tstComponent = Assembly.LoadFile(BBB);
            Type Global = tstComponent.GetType(ClassInBBB, false, true);
if (Global != null)
            {

                EventInfo l_objevent = Global.GetEvent("OnGetdelInBBB");
                Type l_objEveType = l_objevent.EventHandlerType;
                Type Dis = Assembly.GetExecutingAssembly().GetType("AAA", false, true);
                MethodInfo l_method = Dis.GetMethod("HandlerinAAA");
                Delegate d = Delegate.CreateDelegate(l_objEveType, l_method);//Getting argument bind exception in this line
                MethodInfo addHandler = l_objevent.GetAddMethod();
                Object[] addHandlerArgs = { d };
                addHandler.Invoke(Dis, addHandlerArgs);

             }   

please help me. Thanks in advance

1 Answer 1

1

See How to: Hook Up a Delegate Using Reflection

In your code sample your state an exception - that can happen for a number of reasons, but my gut says it is because the method signatures are not correct. You may want to also try a different overload which accepts the object as the second parameter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.