Considering the largely language-agnostic .NET Framework including class library and runtime, and the fact the DLR is supported by multiple languages, I find it odd that a subclassed System.Dynamic.DynamicObject in a C# application actually throws an Exception that’s in the CSharp namespace. I catch the following exception when trying to access a member on dynamic that doesn’t exist at runtime:
{Name = "RuntimeBinderException" FullName = "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException"}
Is the RuntimeBinderException exception specific to C# and if so, must each language implement its own binder exception? It strikes me as odd why the exception is not in a more general namespace and that makes me wonder “what’s up”?
I’m running in Debug mode in VS 2012 Express on .NET 4.5. The application was built in C#.
The reason you are getting an exception in the
CSharpnamespace is because the DLR has determined that thedynamicobject in question is a C# object, and has passed it off to the C# runtime binder for handling.Each language that supports the DLR would need its own implementation of this runtime binding system, and each would depend on the semantics of the language. For example, languages like JScript, which supports on-the-fly property and method creation, would probably not throw an exception on every binding failure, but set or return a new property.
So the answer is, yes, each language that wanted to throw an exception on a DLR binding failure would have to implement it separately.
(As another example: VB.NET’s support for dynamic objects works exactly the same as it’s existing late binding support; you would get the same errors from a DLR binding failure as you would a late-binding
IDispatchfailure, for example, so it didn’t need a separate exception.)