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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:48:23+00:00 2026-05-11T19:48:23+00:00

Does anyone know of a way to intercept dynamic method calls (particularly those that

  • 0

Does anyone know of a way to intercept dynamic method calls (particularly those that are going to raise RuntimeBinderExceptions) with a RealProxy? I was hoping to catch the exception and implement ‘method missing’ on top of that, but it appears to be thrown before the interceptor gets a look-in.

My test just looks like:

dynamic hello = MethodMissingInterceptor<DynamicObject>.Create();
Assert.AreEqual("World", hello.World());

Where World isn’t actually implemented on DynamicObject. The interceptor is pretty straightforward – I was hoping to check IMethodReturnMessage.Exception for RuntimeBinderException and forward on to something like:

public IMessage MethodMissing(IMethodCallMessage call)
{
    return new ReturnMessage(call.MethodBase.Name, new object[0], 0, call.LogicalCallContext, call);
}

Unfortunately, all I see in my interceptor are some calls to GetType, and not the non-existant World method.

Failing that – does anyone know if there’s a DynamicProxy version running happily on .NET 4.0 yet that might have tackled the problem?

  • 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-11T19:48:24+00:00Added an answer on May 11, 2026 at 7:48 pm

    I’ll start with the long answer. Every bind of a dynamic operation in C# does approximately these three things in this order:

    1. Ask the object to bind itself if it implements IDynamicMetaObjectProvider or is a COM object, and if that fails, then…
    2. Bind the operation to an operation on a plain-old-clr-object using reflection, and if that fails, then…
    3. Return a DynamicMetaObject that represents a total failure to bind.

    You’re seeing the GetType calls because in step 2, the C# runtime binder is reflecting over you to try to figure out if you have a “World” method that is appropriate to call, and this is happening because the IDynamicMetaObjectProvider implementation of hello, if there is one, couldn’t come up with anything special to do.

    Unfortunately for you, by the time the RuntimeBinderException is thrown, we are no longer binding. The exception comes out of the execution phase of the dynamic operation, in response to the meta object returned due to step 3. The only opportunity for you to catch it is at the actual call site.

    So that strategy isn’t going to work out for you if you want to implement method_missing in C#. You do have some options though.

    One easy option is to implement IDynamicMetaObjectProvider in your MethodMissingInterceptor, and defer to the IDMOP implementation of the wrapped object. In case of failure on the part of the inner IDMOP, you can bind to whatever you want (perhaps a call to a method_missing delegate stored in the interceptor). The downside here is that this only works for objects that are known to be dynamic objects, e.g. those that implement IDMOP to begin with. This is because you are basically inserting yourself between steps 1 and 2.

    Another alternative I can think of is to implement IDynamicMetaObjectProvider, and in it, respond positively to every bind, returning a call to a method that (a) produces the same code the C# compiler would have produced to bind in the first place, and (b) catches RuntimeBinderException to call a method_missing method. The downside here is that it would be quite complicated–you’d need to generate arbitrary delegate types and the IL that uses them, against the public types in the C# runtime binder assembly which, frankly, are not meant for public consumption. But at least you’d get method missing against all operations.

    I am sure there are other strategies I have not thought of, such as you seem to be hinting at about using remoting proxies. I can’t imagine what they look like though and I can’t say if they’d be successful.

    The crux of the problem here is that C# 4.0 does not have a design that anticipates your desire to do this. Specifically, you cannot easily insert yourself between steps 2 and 3. That brings me to the short answer, which is sorry, C# 4.0 does not have method_missing.

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

Sidebar

Related Questions

Does anyone know a way to make an asp button... <asp:button runat=server>Button1</asp:button> resemble an
Does anyone know the way to hide public classes in JAR file. In other
Does anyone know a way to produce a nice publication quality LaTeX table from
Does anyone know a way get the pixel data from a PythonMagick.Image instance without
I'm trying to find a way with a batch file that will delete specific
I need to get N instances of an object where I won't know N
My Client wants to be able to build our project from source but does
I have an android app that connects to the internet to do a reverse
Can someone check this calculation? I want to calculate the speed of my internet
With my only ORM knowledge being L2S/EF, I was surprised when the following code

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.