24

I'm getting an unexpected RuntimeBinderInternalCompilerException when passing an object as a dynamic argument.

I'll try to explain the scenario, as it's too involved to paste code easily. I'm doing some really weird hackery with Roslyn, so it's going to sound odd.

  1. Execute application
  2. Monitor source code for changes
  3. Recompile what is effectively a diff of the assembly with the changed files/classes
  4. Load the new compiled assembly into the original AppDomain
  5. Pass existing object instances to the new/changed code as Dynamic, so the new code can operate on existing context/application state.

This dynamic passing should work, because the type is compatible: i.e., in my case I can guarantee it has functionally matching methods/types.

But when I go to execute the changed+reloaded method, and it receives an object of type dynamic, I'm getting this exception.

RuntimeBinderInternalCompilerException was unhandled.
An unexpected exception occurred while binding a dynamic operation

Per MSDN:

Exceptions of this kind differ from RuntimeBinderException in that RuntimeBinderException represents a failure to bind in the sense of a usual compiler error, whereas RuntimeBinderInternalCompilerException represents a malfunctioning of the runtime binder itself.

Google has absolutely no results for this. I don't know how to debug further into it either. Any suggestions?

( I did do some sandbox testing to assure myself that I could load different assemblies at runtime into a test application and pass instanced types from different assemblies to a single method accepting a dynamic parameter. So it does work in that scenario. )

12
  • 2
    I'm afraid that without actual code, we won't be able to help you. Could you simplify your code as much as possible, but so that it still shows the error and post it here? And in any case, it looks like a bug in dynamic, so you might want to post it to Connect. Commented Aug 28, 2012 at 10:20
  • Yes, this looks like an actual bug in the Runtime binder and if you can, you should try to create a minimal repro and post it on Connect. Unfortunately I don't think we'll be able to fix it in the near future, so you'll have to find a workaround. Commented Aug 29, 2012 at 17:24
  • I've been trying to put together a reasonably simple repro case, but I haven't been able to easily narrow it down yet. I'll give it another shot though. Commented Aug 29, 2012 at 21:47
  • 2
    Any news about this problem? I am facing a similar situation. Commented Apr 26, 2013 at 23:37
  • Nope, still stands. I basically dropped my project because I couldn't find a workaround, and it's a low priority bug. Commented Apr 27, 2013 at 20:41

1 Answer 1

2

It's difficult to answer the question without more details, but reading what you've said, there are a few things to note:

  1. Internally, all type names are fully qualified. This means that the compiler will reject your code if you try to treat two types as the same unless they are from the same assembly, with the same namespace and name. Getting slightly different types to mesh in .Net is tricky.

  2. dynamic doesn't always work as you might intuitively think. If you're playing with the compiler, it's very much worth learning how IL works, and looking at both your code and the base-class-library code to see how they interact.

A very useful tool for low-level .Net work is ILSpy: http://ilspy.net/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.