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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:51:59+00:00 2026-06-18T08:51:59+00:00

I was looking at the question Use ‘dynamic’ throw a RuntimeBinderException . I face

  • 0

I was looking at the question Use ‘dynamic’ throw a RuntimeBinderException. I face a similar problem:

Basically, I want to create a “HTML helper” in ASP.NET MVC that uses dynamic arguments, akin to the htmlArguments parameter for many of the existing helpers (more code below):

public BootstrapCell(Action<string> emitContentAction, dynamic args)

View:

@using (grid.Cell(ViewContext.Writer.Write, new {Position = 4}))
{
     <p>zomg!</p>
}

However in the naive approach, i get RuntimeBinderException thrown at me, declaring that 'object' does not contain a definition for 'Position', even though when debugging and hovering over the _args variable, it clearly does have a Position property.

The caller and the callee are in separate assemblies. Why is that problem happening?

(The solution to that has been shown in the same question: Manually create an ExpandoObject to hold the args.)

Implementation:

public class Cell
{
    private readonly string _tagName;
    private dynamic _args;
    private Action<string> EmitContentAction;

    public BootstrapCell(Action<string> emitContentAction, dynamic args) : DisposableBaseClass
    {
        _args = args;
        EmitContentAction = emitContentAction;
        OnContextEnter();
    }

    protected void OnContextEnter()
    {
        var sb = new StringBuilder("<");
        sb.Append(_tagName);

        if (_args.Position > 0)
        {
            sb.Append(" class=\"offset");
            sb.Append(args.Position);
            sb.Append("\"");
        }

        sb.Append(">");

        EmitContentAction(sb.ToString());
    }
}

[Edited to make clearer that my problem arises when “obviously” the Position property is set. I am aware that if the property never was defined in the first place, an exception must be raised.]

  • 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-18T08:52:00+00:00Added an answer on June 18, 2026 at 8:52 am

    That code is fatally flawed.

    It does work, as long as you specify that property:

    void Bar()
    {
        Foo(new {Position = 0});
    }
    
    void Foo(dynamic args)
    {
        Console.WriteLine(args.Position);
    }
    

    That will output 0, it will not throw a RuntimeBinderException.

    But the purpose of such code is the possibility for the caller to specify only the properties needed and omit the rest.
    You are trying to check for this omission via if(args.Position != null). But that doesn’t work, it already requires Position to exist.

    When you have a look at the routing API of ASP.NET that also supports those anonymous configuration objects you will notice that the type of the parameter is object and not dynamic.
    Using object instead of dynamic will enable your API to be used across assembly boundaries.

    So how does it work?

    Just like in the linked answer, you need to manually create a dictionary of the properties. Whether you use a plain old Dictionary<string, object> or an ExpandoObject is a matter of preference.
    Using ExpandoObject will make your code a bit simpler to read and write, but it is not required.


    About the actual exception you are getting:
    Please note that it tells you it can’t find the Position property on object. If it would be an anonymous type that was missing the Position property the exception message wouldn’t refer to object but to an anonymous type. Something like this:

    '<>f__AnonymousType0' does not contain a definition for ‘Position’

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

Sidebar

Related Questions

Thanks for looking at this question. I wanted to know how can I use
I was looking at this question. Basically having a leading zero causes the number
This is a very specific question: I am looking to use normals in post
Not Looking for a Use Framework XXX Answer This question is not intended for
Simple question... I want to use Ninject Interceptors to take care of my NFRs,
Thanks for looking at my question. I want to get the mobile version by
This is perhaps a crazy question but I am looking to use a UIButton
I was looking at this question here : How do I use extern to
After looking at this question , I think I want to wrap ThreadLocal to
This is related to a question I asked here: Thread Locking in Ruby (use

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.