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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:56:22+00:00 2026-05-27T21:56:22+00:00

Is it possible to call a protected method via reflection. I am using this:

  • 0

Is it possible to call a protected method via reflection. I am using this:

 Me.GetType.InvokeMember(Stages(CurrentStage), 
                         Reflection.BindingFlags.InvokeMethod, 
                         Nothing, 
                         Me, 
                         Nothing)

Which always calls a method with no params or return. The idea is that the user of my object (transactional processing of business logic) inherits the base class adds in a load of private methods to fire. They then add these method names to a list in the order they would like them fired and the code above will take care of firing them.

It works fine with public methods but not with private or protected methods in the same class (Protected because I have some ‘standard’ pre built methods to add to the base class). Realistically I could make the methods public and be done with it but my inner nerd wont allow me to do so…

I am assuming this is a security feature. Is there a way to get around this or does anyone have any suggestions on how to proceed but keep my tasty, tasty visibility modifiers in tact?

(NOTE: ITS IN VB.NET but a C# Answer is fine if that is what you are comfortable with).

  • 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-27T21:56:23+00:00Added an answer on May 27, 2026 at 9:56 pm

    If you are invoking the methods on an instantiated object, you will also need BindingFlags.Instance. So the code would look like (Note: I’ve also added the BindingFlags option to include public members in the search):

    Me.GetType.InvokeMember(Stages(CurrentStage), 
                            BindingFlags.InvokeMethod Or BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.Instance, 
                            Nothing, 
                            Me, 
                            Nothing)
    

    For more information on how to use this, refer to the MSDN Documentation.

    EDIT

    To support this answer, I have written a test program that demonstrates the invocation of public, protected and private class methods. I have uploaded all classes to PasteBin. There are three classes that make up a C# Console Application, so can be added to a Visual Studio solution and run to test.

    • Program.cs – Sets up the methods to be invoked (contained within the SomeClass class). Executes the invocation and prints the results.
    • SomeClass.cs – Contains three methods of each of the visibility modifiers: public, protected and private. Also registers itself and the three contained methods for invocation by the Invoker class.
    • Invoker.cs – Accepts registration of types and methods that are to be invoked. Then enumerates the registered types and invokes the methods, building an enumerable collection of results.

    Feel free to look over that code and see if you can find any differences in how you are approaching it. I appreciate it may not be the simplest of approaches, though. Let me know if you have any further queries on it.

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

Sidebar

Related Questions

is it possible to call a method using a regular hyperlink like so: <div
Is it possible to call into COM objects via x86 assembly language? If so,
How is it possible to call a client side javascript method after a specific
Possible Duplicate: Why is the finalize() method in java.lang.Object “protected”? The finalize method is
Is it possible to call a COM API from Java (specifically the HP/Mercury Quality
Is it possible to call managed code, specifically IronRuby or IronPython from unamanaged code
Is it possible to call a JavaScript function from the IMG SRC tag to
is it somehow possible to call a rails function or to access a rails
Is it possible to call a constructor from another (within the same class, not
Is is possible to call a custom VB function, saved in the same Access

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.