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

The Archive Base Latest Questions

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

When implementing dynamic dispatch using dynamic on a generic class, and the generic type

  • 0

When implementing dynamic dispatch using dynamic on a generic class, and the generic type parameter is a private inner class on another class, the runtime binder throws an exception.

For example:

using System;

public abstract class Dispatcher<T> {
    public T Call(object foo) { return CallDispatch((dynamic)foo); }

    protected abstract T CallDispatch(int foo);
    protected abstract T CallDispatch(string foo);
}

public class Program {
    public static void Main() {
        TypeFinder d = new TypeFinder();

        Console.WriteLine(d.Call(0));
        Console.WriteLine(d.Call(""));
    }

    private class TypeFinder : Dispatcher<CallType> {
        protected override CallType CallDispatch(int foo) {
            return CallType.Int;
        }

        protected override CallType CallDispatch(string foo) {
            return CallType.String;
        }
    }

    private enum CallType { Int, String }
}

Here, a RuntimeBinderException will be thrown with the message

‘Dispatcher.CallDispatch(int)’ is inaccessible due to its protection level

The reason for the inaccessibility is that the type parameter T is the private CallType which Dispatcher<T> cannot access. Therefore, CallDispatch must be inaccessible – but it isn’t, because it’s accessible as T.

Is this a bug with dynamic, or is this not supposed to be supported?

  • 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-22T21:03:31+00:00Added an answer on May 22, 2026 at 9:03 pm

    It’s a bug. If you can make the call statically (and you can), you should be able to make it dynamically.

    Specifically, the following code works:

    using System;
    
    public abstract class Dispatcher<T> {
        public T Call(object foo)
        {
            return CallDispatch(((object)(dynamic)foo).ToString());
        }
    
        protected abstract T CallDispatch(int foo);
        protected abstract T CallDispatch(string foo);
    }
    
    public class Program {
        public static void Main() {
            TypeFinder d = new TypeFinder();
    
            Console.WriteLine(d.Call(0));
            Console.WriteLine(d.Call(""));
        }
    
        private class TypeFinder : Dispatcher<CallType> {
            protected override CallType CallDispatch(int foo) {
                return CallType.Int;
            }
    
            protected override CallType CallDispatch(string foo) {
                return CallType.String;
            }
        }
    
        private enum CallType { Int, String }
    }
    

    Note that I’ve used ToString() to make the static type known, the C# compiler and CLR allow this context to access the private type CallType, so the DLR should allow it as well.

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

Sidebar

Related Questions

Any re-sources or best-practices for implementing dynamic class re-loading feature into a J2EE WebApp
While implementing a design using nested generic collections, I stumbled across those limitations apparently
I did a little experiments with Ruby class dynamic loading/unloading/updating as implementing plugins infrastructure.
I´m having some trouble implementing a dynamic tree structure using the primefaces tree implementation.
implementing publishActivity in PHP using the REST API using this code: $activity = array(
I've seen a lot of questions around here about implementing dynamic forms in jQuery
I am implementing a dynamic programming algorithm for the knapsack problem in Java. I
I am implementing a dynamic application for 4 desktops in my house so i
I am implementing a templated sparse_vector class. It's like a vector, but it only
Shortly: how to determine if id is CFType or not at runtime i'm implementing

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.