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 907127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:30:07+00:00 2026-05-15T16:30:07+00:00

I got stuck up while dynamically assigning methods to a delegate instance through reflection.

  • 0

I got stuck up while dynamically assigning methods to a delegate instance through reflection. Below is a sample scenario of the situation i am faced with.

class Program
{
    static void Main(string[] args)
    {
        new DynamicDelegateTest().Test();            
    }
}

public class DynamicDelegateTest
{
    public void Test()
    {
        //This is what i target to do through reflection
        ABC objABC1 = new ABC();
        objABC1.Proc = Debugger;
        objABC1.Test("Helloz");

        //Implementing the same code through reflection
        ABC objABC = new ABC();
        MethodInfo MIDebugger = GetType().GetMethod("Debugger", BindingFlags.NonPublic | BindingFlags.Instance);
        FieldInfo MyProc = objABC.GetType().GetField("Proc", BindingFlags.Public | BindingFlags.Instance);

        //This is the point where I got stuck up
        MyProc.SetValue(objABC, MIDebugger);
        objABC.Test("QWERTY");  
    }

    void Debugger(object Tests)
    {
        Console.WriteLine(Tests);
    }
}

public class ABC
{
    public delegate void Delg(object P1);
    public Delg Proc;

    public void Test(object Tst)
    {
        if (Proc != null) Proc(Tst);
    }
}

Please Help.

  • 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-15T16:30:08+00:00Added an answer on May 15, 2026 at 4:30 pm

    You need to use Delegate.CreateDelegate to get the delegate instance, rather than a method-info. For non-static methods this also includes the target instance. In this case:

    object del = Delegate.CreateDelegate(MyProc.FieldType, this, MIDebugger);
    MyProc.SetValue(objABC, del);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got stuck while adding records to contacts of iphone. Situation is this I
Trying to use the GregorianCalendar, I got stuck on a singularity while computing the
Got stuck while trying to make an element in website behave like this: <div
i got stuck while implementing one webservice in iPhone, i think something is wrong
While trying to apply policy-based design, I got stuck on this one (simplified): template
I'm trying to go through Hibernate tutorial and got stuck on running the command
I got stuck with a performance problem while writing my program and I need
I've been working on a project for a while but got stuck where I
While attempting to provide an implimentation to this question , I got stuck on
while learning some basic programming with python, i found web.py. i got stuck with

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.