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

  • Home
  • SEARCH
  • 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 531191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:16:30+00:00 2026-05-13T09:16:30+00:00

I have an implementation building a delegate handler collection. public class DelegateHandler { internal

  • 0

I have an implementation building a delegate handler collection.

   public class DelegateHandler
   {
            internal delegate object delegateMethod(object args);
            public IntPtr PublishAsyncMethod(MethodInfo method, MethodInfo callback)
            {
                RuntimeMethodHandle rt;

                try
                {
                    rt = method.MethodHandle;
                    delegateMethod dMethod = (delegateMethod)Delegate.CreateDelegate
                        (typeof(delegateMethod), method.ReflectedType, method, true);
                    AsyncCallback callBack = (AsyncCallback)Delegate.CreateDelegate
                        (typeof(AsyncCallback), method.ReflectedType, callback, true);

                    handlers[rt.Value] = new DelegateStruct(dMethod, callBack);
                    return rt.Value;
                }
                catch (System.ArgumentException ArgEx)
                {
                    Console.WriteLine("*****: " + ArgEx.Source);
                    Console.WriteLine("*****: " + ArgEx.InnerException);
                    Console.WriteLine("*****: " + ArgEx.Message);
                }

                return new IntPtr(-1);
            }
   }

I publish using the following:

 ptr = DelegateHandler.Io.PublishAsyncMethod(
    this.GetType().GetMethod("InitializeComponents"),
    this.GetType().GetMethod("Components_Initialized"));

And the method I’m creating a delegate from:

    public void InitializeComponents(object args)
    { 
           // do stuff;
    }

And the callback method:

public void Components_Initialized(IAsyncResult iaRes)
{
       // do stuff;
}

Now, I’ve also already looked at this to get an idea of what I might be doing wrong. The CreateDelegate(…) is causing me to receive:

*****: mscorlib
*****: 
*****: Error binding to target method.

What is wrong? The methods reside in a different, non-static public class. Any help would be greatly appreciated.

NOTE: These methods will have parameters and return values. As I understand Action, and Action<T>, this would not be an option.

  • 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-13T09:16:30+00:00Added an answer on May 13, 2026 at 9:16 am

    There are 2 problems.

    First, you are passing incorrect arguments to CreateDelegate. Since you are binding to instance methods, you need to pass the instance to which the delegates will be bound, but you are passing method.ReflectedType instead of a reference to an object of the class that declares InitializeComponents and Components_Initialized.

    Second, the signature of InitializeComponents does not match the declaration of delegate dMethod. The delegate has an object return type yet InitializeComponents returns void.

    The following should work:

    // return type changed to void to match target.
    internal delegate void delegateMethod(object args);
    
    // obj parameter added
    public static void PublishAsyncMethod(object obj, MethodInfo method, MethodInfo callback)
    {
        delegateMethod dMethod = (delegateMethod)Delegate.CreateDelegate
            (typeof(delegateMethod), obj, method, true);
    
        AsyncCallback callBack = (AsyncCallback)Delegate.CreateDelegate
             (typeof(AsyncCallback), obj, callback);
    
    }
    
    DelegateHandler.PublishAsyncMethod(
        this, // pass this pointer needed to bind instance methods to delegates.
        this.GetType().GetMethod("InitializeComponents"),
        this.GetType().GetMethod("Components_Initialized"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 310k
  • Answers 310k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I got it , SomeStudentRelation.HasItems() to check if it has… May 13, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer You can return an instance of an anonymous type from… May 13, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer As written, A, by a longshot. The issue, quite simply,… May 13, 2026 at 10:14 pm

Related Questions

See Also: understanding events and event handlers in C# As a web dev, I
I'm building an emailing system for a framework I'm developing. Thus far, I've got
I'm trying to populate a UITableview with an array of cells. I usually do
I've been building a WCF app behind 3 projects (contract,implementation,client) I've hosted my service
I'm using a lot of JQuery in a web application that I am building

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.