Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeBinderInternalCompilerException on Dynamic call

Tags:

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. )

like image 427
Kal_Torak Avatar asked Aug 28 '12 09:08

Kal_Torak


1 Answers

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/

like image 197
Iain Ballard Avatar answered Oct 18 '22 22:10

Iain Ballard