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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:44:46+00:00 2026-05-25T12:44:46+00:00

Consider the following example program: using System; public delegate string MyDelegateType(int integer); partial class

  • 0

Consider the following example program:

using System;
public delegate string MyDelegateType(int integer);

partial class Program
{
    static string MyMethod(int integer) { return integer.ToString(); }

    static void Main()
    {
        Func<int, string> func = MyMethod;

        // Scenario 1: works
        var newDelegate1 = new MyDelegateType(func);
        newDelegate1(47);

        // Scenario 2: doesn’t work
        dynamic dyn = func;
        var newDelegate2 = new MyDelegateType(dyn);
        newDelegate2(47);
    }
}

The first one works as expected — the conversion to MyDelegateType succeeds. The second one, however, throws a RuntimeBinderException with the error message:

Cannot implicitly convert type ‘System.Func<int,string>’ to ‘MyDelegateType’

Is there anything in the C# specification that allows for this behaviour, or is this a bug in Microsoft’s C# compiler?

  • 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-25T12:44:46+00:00Added an answer on May 25, 2026 at 12:44 pm

    Good catch Timwi.

    Our support for dynamic method groups is weak. For example, consider this simpler case:

    class C
    {
      public void M() {}
    }
    
    class P
    {
        static void Main()
        {
            dynamic d = new C();
            C c = new C();
            Action a1 = c.M; // works
            Action a2 = d.M; // fails at runtime
    

    The d.M is interpreted as a property get (or field access) by the dynamic runtime, and when it resolves as a method group, it fails at runtime.

    The same thing is happening in your case, it is just a bit more obscure. When you say MyDelegate x = new MyDelegate(someOtherDelegate); that is treated by the compiler just as if you’d said MyDelegate x = someOtherDelegate.Invoke;. The dynamic runtime piece does not know to do that transformation, and even if it did, it couldn’t handle resolving the method group that is the result of the .Invoke portion of the expression.

    Is there anything in the C# specification that allows for this behaviour, or is this a bug in Microsoft’s C# compiler?

    The spec does not call out that this should be a runtime error, and does imply that it should be handled correctly at runtime; clearly the implementation does not do so. Though it is a shortcoming of the implementation I wouldn’t call this a “bug” because we deliberately made the behaviour you’ve discovered. We did not have the resources to make these kinds of expressions work exactly right, so we left them as errors. If we ever get a good way to represent method groups in the dynamic runtime, we might implement it.

    Similarly there is no way in dynamic code to represent the notion of “this dynamic thing is a lambda expression where the types of the parameters are to be determined at runtime”. If we have a good way to represent those in the future, we might do the work.

    Sam talked a bit about this back in 2008; see his article on it:

    http://blogs.msdn.com/b/samng/archive/2008/11/02/dynamic-in-c-ii-basics.aspx

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

Sidebar

Related Questions

Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following example program: next :: Int -> Int next i | 0
Consider the following example: public interface ITask { void Execute(); } public class LoggingTaskRunner
consider the following example: public IEnumerable<String> Test () { IEnumerable<String> lexicalStrings = new List<String>
Consider the following example: public class Sandbox { public interface Listener<T extends JComponent> {
Consider this demo program: #include <stdio.h> class Base { public: virtual int f(int) =0;
Consider the following example. String str = new String(); str = "Hello"; System.out.println(str); //Prints
Consider the following example: template <typename T> class A { public: void f() {
Consider the following example: int size = 10, *kk = new int[size]; for (int
Consider the following code (written with Visual Studio 2010 and .NET 4.0) using System;

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.