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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:06:19+00:00 2026-06-05T23:06:19+00:00

I am currently running into an issue trying to create delegates from MethodInfo .

  • 0

I am currently running into an issue trying to create delegates from MethodInfo. My overall goal is to look through the methods in a class and create delegates for ones marked with a certain attribute. I am trying to use CreateDelegate but I am getting the following error.

Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.

Here is my code

public class TestClass
{
    public delegate void TestDelagate(string test);
    private List<TestDelagate> delagates = new List<TestDelagate>();

    public TestClass()
    {
        foreach (MethodInfo method in this.GetType().GetMethods())
        {
            if (TestAttribute.IsTest(method))
            {
                TestDelegate newDelegate = (TestDelagate)Delegate.CreateDelegate(typeof(TestDelagate), method);
                delegates.Add(newDelegate);
            }
        }
    }

    [Test]
    public void TestFunction(string test)
    {

    }
}

public class TestAttribute : Attribute
{
    public static bool IsTest(MemberInfo member)
    {
        bool isTestAttribute = false;

        foreach (object attribute in member.GetCustomAttributes(true))
        {
            if (attribute is TestAttribute)
                isTestAttribute = true;
        }

        return isTestAttribute;
    }
}
  • 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-06-05T23:06:21+00:00Added an answer on June 5, 2026 at 11:06 pm

    You’re trying to create a delegate from an instance method, but you’re not passing in a target.

    You could use:

    Delegate.CreateDelegate(typeof(TestDelagate), this, method);
    

    … or you could make your method static.

    (If you need to cope with both kinds of method, you’ll need to do that conditionally, or pass in null as the middle argument.)

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

Sidebar

Related Questions

So i am running into a major issue. I am currently trying to use
I'm currently using Entity Framework and am running into this issue: The relationship between
FYI, ShadowBox is a javscript media viewer/lightbox. http://www.shadowbox-js.com/ Running into an issue when trying
I am trying to fetch and display contents from table.Currently i am running a
I'm running into an issue where ReadToEnd is throwing an OutOfMemory exception when trying
I'm currently running into trouble configuring MAMP 2 to use SSL with multiple virtual
We are currently developing an application for a msp430 MCU, and are running into
I'm trying to create am immutable type (class) in C++, I made it so
I'm a relatively inexperienced coder and I've been running into an issue with getting
So I'm running into an interesting issue implementing session ID rolling after log-in/change of

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.