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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:17:19+00:00 2026-06-17T05:17:19+00:00

Inspired by this question I have tried a following code on Mono 2.10.9 and

  • 0

Inspired by this question I have tried a following code on Mono 2.10.9 and Visual Studio 2010:

public class Example
{
    public static void Main()
    {
        Foo(1);
    }

    public static void Foo( dynamic x )
    {
        Example.Bar(x);
    }

    static void Bar( dynamic x )
    {
        x++;
    }

    int count;
    void Bar( int x )
    {
        count++;
    }
}

As you can see, Foo is static, so it can only access static Bar – and I explicitly invoke the static version!

I know that I would not be able to declare static void Bar( int x ), because a non-static version exists.

However, changing the argument type of non-static Bar to, let’s say, string, makes everything alright.

Why is that? What are the rules here? Is it possible to call the static method?

Maybe it’s a Mono DLR issue?

EDIT: For clarification. I would like to know what rules turn an explicit call to static method (at least I think it’s explicit) into a call to a non-static one? This is obviously impossible from static context.

Or, if there are no such rules, can it be a bug? Can this behaviour be somehow avoided?

  • 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-17T05:17:20+00:00Added an answer on June 17, 2026 at 5:17 am

    The key statement there is that “I know that I would not be able to declare static void Bar( int x ), because a non-static version exists.”. Using the dynamic keyword defers the overload resolution to run-time, but it doesn’t exempt you from that rule when run-time comes along.

    When that overload resolution finally occurs, the DLR evaluates all the options available and then chooses the best one. Until this resolution-time, parameters of dynamic type behave much like being of type object (see here). So normally the more specific method that takes an int would be the winner in the overoad resolution and thus be chosen over the one that takes a dynamic/object. This means that the instance method would normally win. The DLR knows that two methods with the same signature cannot vary by staticness. When evaluating the options available, what you are expecting it to do is say “aha! In this case, static void Bar(dynamic x) can be interpreted as static void Bar(int x)”. However, if it did say that, then the rule about not having otherwise identical static and non-static methods would be violated. It’s internal list of options would contain the static and non-static Bar methods, both of which would have the same signature. So it can’t say that. This leaves the only other option, which happens to be an instance method. This is no use in the circumstances so the DLR throws a RuntimeBinderException. If you change the parameter of the instance Bar to something other than an int, then the method signatures do not clash, so the DLR can interpret the static dynamic Bar as taking an int and select that overload instead.

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

Sidebar

Related Questions

Using the following code, and inspired by this question, I managed to have vertical
Inspired by this question . Suppose in C++ code I have a valid pointer
Inspired by the discussion in this question . We have all been taught that
Inspired by this SO question : Why doesn't C# have a keyword for non-virtual
This question is inspired from Joel's Making Wrong Code Look Wrong http://www.joelonsoftware.com/articles/Wrong.html Sometimes you
This question is inspired in the following solution to multiple inheritance overloading pseudo-ambiguity, which
The following question is inspired by this blog entry at ajaxian.com and this comment
A different question inspired the following thought: Does std::vector<T> have to move all the
Inspired by this earlier stack overflow question I have been considering how to randomly
This question inspired me to ask the following question. Does the DllImport attribute always

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.