Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

497
Views
C# - GetMethod returns null

I have A class:

public abstract class A
{

}

And then I have B class that derives from it:

public sealed class B : A
{
    public void SomeMethod()
    {
        var method = this.GetType().GetMethod("AddText");
    }

    private void AddText(string text)
    {
        ...
    }
}

Why is GetMethod returning null?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

var methodInfo = this.GetType().GetMethod("AddText", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(string) }, null);

Your method has a parameter, you need to use the overload that accepts a type array for the parameter types and the binding flags.

In .net Method signatures are based on their name, their return type, and their parameters.

So if your method has parameters you have to tell Reflection what parameter types it has via a Type[].

over 4 years ago · Santiago Trujillo Report

0

By default, Reflection will only search for public methods.

You need to pass BindingFlags.Instance | BindingFlags.NonPublic.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!