Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3214682
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:05:22+00:00 2026-05-17T15:05:22+00:00

I am trying to hook Up a Delegate Using Reflection. This is what I

  • 0

I am trying to hook Up a Delegate Using Reflection. This is what I have done so far

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Data;
using System.Threading;
using System.IO;
using System.Reflection;
using System.Windows;

namespace ChartHelper
{
    public class ICChartHelper
    {        

        public void RefreshChart()
        {
            try
            {   
                Assembly myobj = Assembly.LoadFrom(@"C:\sample.dll");

                foreach (Type mytype in myobj.GetTypes())
                {

                    if (mytype.IsClass == true)
                    {
                        if (mytype.FullName.EndsWith("." + "ICAutomationProxy"))
                        {
                            // create an instance of the object
                            object ClassObj = Activator.CreateInstance(mytype);

               //  var eventTypes = mytype.GetEvents();

                            EventInfo evClick = mytype.GetEvent("OnRefreshCompleted");
                            Type tDelegate = evClick.EventHandlerType;

                            MethodInfo miHandler =
                           typeof(ChartHelper.ICChartHelper)
                           .GetMethod("RefreshApplication",
                            BindingFlags.NonPublic | BindingFlags.Instance);

                            Delegate d = Delegate.CreateDelegate(tDelegate,typeof(ChartHelper.ICChartHelper), miHandler);

                            MethodInfo addHandler = evClick.GetAddMethod();
                            Object[] addHandlerArgs = { d };
                            addHandler.Invoke(ClassObj, addHandlerArgs);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void RefreshApplication(Object sender, EventArgs e)
        {
            MessageBox.Show("Bingo");
        }

But in the

Delegate d = Delegate.CreateDelegate(tDelegate,typeof(ChartHelper.ICChartHelper), miHandler);

line, I am encountering the error Error binding to target method

I have also found the discusion here and tried to solve the same but with no luck.

I need help to understand what wrong I am doing?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:05:23+00:00Added an answer on May 17, 2026 at 3:05 pm

    Your method is an instance method, so you need to use an overload of CreateDelegate which takes the target of the delegate, and pass in an instance of the declaring type. For example:

    Delegate d = Delegate.CreateDelegate(tDelegate, new ICChartHelper(), miHandler);
    

    Note that you don’t need to call GetAddMethod on the EventInfo and invoke that using reflection – you can just use EventInfo.AddEventHandler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I'm trying to hook up a blog with some xml namespaces and xml stylesheets.
I'm trying to write a bzr post-commit hook for my private bugtracker, but I'm
Trying to get my css / C# functions to look like this: body {
Trying to make a make generic select control that I can dynamically add elements
Trying to keep all the presentation stuff in the xhtml on this project and
I'm trying to hook a 3rd party app so that I can draw to
Trying to hook into the function comment_text() supplied by Wordpress API to wrap the
I am trying to hook for example Notepad without sucess. Making a global hook
I'm just trying to hook Trac/SVN together so that my SVN commits manage my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.