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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:06:43+00:00 2026-05-14T06:06:43+00:00

Code below is working well as long as I have class ClassSameAssembly in same

  • 0

Code below is working well as long as I have class ClassSameAssembly in same assembly as class Program.
But when I move class ClassSameAssembly to a separate assembly, a RuntimeBinderException (see below) is thrown.
Is it possible to resolve it?

using System;

namespace ConsoleApplication2
{
    public static class ClassSameAssembly
    {
        public static dynamic GetValues()
        {
            return new
            {
                Name = "Michael", Age = 20
            };
        }
    }

    internal class Program
    {
        private static void Main(string[] args)
        {
            var d = ClassSameAssembly.GetValues();
            Console.WriteLine("{0} is {1} years old", d.Name, d.Age);
        }
    }
}

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ‘object’ does not contain a definition for ‘Name’

at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at ConsoleApplication2.Program.Main(String[] args) in C:\temp\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 23
  • 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-14T06:06:43+00:00Added an answer on May 14, 2026 at 6:06 am

    I believe the problem is that the anonymous type is generated as internal, so the binder doesn’t really “know” about it as such.

    Try using ExpandoObject instead:

    public static dynamic GetValues()
    {
        dynamic expando = new ExpandoObject();
        expando.Name = "Michael";
        expando.Age = 20;
        return expando;
    }
    

    I know that’s somewhat ugly, but it’s the best I can think of at the moment… I don’t think you can even use an object initializer with it, because while it’s strongly typed as ExpandoObject the compiler won’t know what to do with “Name” and “Age”. You may be able to do this:

     dynamic expando = new ExpandoObject()
     {
         { "Name", "Michael" },
         { "Age", 20 }
     };
     return expando;
    

    but that’s not much better…

    You could potentially write an extension method to convert an anonymous type to an expando with the same contents via reflection. Then you could write:

    return new { Name = "Michael", Age = 20 }.ToExpando();
    

    That’s pretty horrible though 🙁

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

Sidebar

Related Questions

The below mentioned code; worked well on 32 bit machine but its not working
The code below is working, but with a problem I do not understand. When
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
OK, several questions about the test code below... I don't have the full working
I have the CTE below working well in re-cursing an employee table and building
I have the below code working onclick. <form action= name=testform method=post id=testform> <input type=hidden
I have the code below working for various ACE changes and adds and revoking
The code below working for only first div. I can't display other divs when
The code below is working nearly flawlessly, however my value for page title on
The code below is working. It will progress through all columns in the sheet

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.