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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:25:13+00:00 2026-06-15T10:25:13+00:00

When I want to dynamically call a statically-defined (statically in the sense of determined

  • 0

When I want to dynamically call a statically-defined (“statically” in the sense of “determined at compile-time”, not in the sense of “class-level member”) method on any object in C#, I can use reflection to get a handle to that method and invoke it:

typeof(Foo).GetMethod("Bar").Invoke(foo, new object[] { /* params */ });

However, objects made dynamic by inheriting from DynamicObject respond to (undefined) instance method calls using TryInvokeMember, and the dynamic methods the class responds to are not exposed through reflection, for obvious reasons. This means that I can’t get a method handle for a method that should be responded to by TryInvokeMember.

So ironically, it seems to me that you can’t dynamically call a dynamic method on a dynamic object as easily as you can call a defined method on a non-dynamic object.

I’ve considered calling TryInvokeMember directly, but the first argument must be an instance of an InvokeMemberBinder, an abstract class. I feel that if I have to implement a class to call a dynamic method on a dynamic object, I must be doing something wrong.

How can I call a method on a dynamic object by its name, knowing that the target class does not implement it and that it should be responded to using TryInvokeMember?

  • 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-15T10:25:14+00:00Added an answer on June 15, 2026 at 10:25 am

    One way to go about it is to mimic what the C# compiler outputs for method invocations on dynamic objects. This requires the usage of a bunch of types marked [EditorBrowsable(EditorBrowsableState.Never)] in the Microsoft.CSharp.RuntimeBinder namespace, so they will not be visible in Intellisense. Needless to say, this doesn’t seem like a supported scenario, so use it at your own risk!

    This code calls the dynamic Bar method without any arguments on an instance of a class derived from DynamicObject:

    dynamic dynamicObject = new DerivedFromDynamicObject();
    var callSiteBinder = Binder.InvokeMember(CSharpBinderFlags.None, "Bar", Enumerable.Empty<Type>(), typeof(Program),
        new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
    var callSite = CallSite<Action<CallSite, object>>.Create(callSiteBinder);
    callSite.Target(callSite, dynamicObject);
    

    This blog post and this one have more gory details on call sites and binders.

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

Sidebar

Related Questions

I want to dynamically call the method of a custom class much like the
I'm generating buttons dynamically that I want it to call a method like this:
I want to dynamically create instance method of child class through class method of
I want to make a class that has the ability to dynamically call methods
it may be a duplicate of How to dynamically call a class' method in
I want to dynamically call fancybox to load an iframe. The URL of the
I'm not quite sure how to correctly put this question. I want to dynamically
I'm looking for the best way to dynamically call a method from a different
I want to dynamically add triggers to a job, but can't find any helpful
I want to call a function this way redBall(this); but I want to dynamically

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.