Tuesday, May 18, 2010

Silverlight 4.0, Dynamic Types & Extension Methods

I’ve been very busy lately earning my living.  Not able to get time to blog!  But hey, I wanted to hack together something - the DynamicMvvM framework which I had hinted about earlier - over this weekend.  This got me working with the beauty that is DynamicObject (and ExpandoObject) in C# 4.0.

The first error I had hit was probably the one every one working with DynamicObject for the first time encounters:

Error    2    Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported    TestApp
Error    3    One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?   

True enough when I did add Microsoft.CSharp.dll and System.Core.dll, the errors went away.

Using a keyword in C# requires me to add some assemblies?  Oops…  Adding these two assemblies to Visual Studio project templates for Silverlight, by default, would be high on my wish list!  Thankfully, these are added by default to WPF projects (the only one I checked) and hopefully other project types.

Another interesting thing about DynamicObject is that when it’s assigned to a dynamic, it’s not able to find ExtensionMethods.  This is reasonable considering all the calls to the methods and properties are resolved at runtime and the ExtensionMethods are not part of the object’s interface per se.

Just one one more piece of info you need to file away for future use.

3 comments:

Mike said...

Your blog has been recommended to us as a interviewee's favorite blog!

We would like to do an interview with you about your blog for Blog
Interviewer. We'd
like to give you the opportunity to
give us some insight on the "person behind the blog."

It would just take a few minutes of your time. The interview form can
be submitted online here Submit your
interview
.

Best regards,

Mike Thomas

KBC said...

I am still getting these errors after adding these dlls. please help

Unknown said...

Yes indeed we still have the error even thought the dll are referenced however in the Watch window, if you jsut put the basic object it'll be resolved then and just then you'll be able to go deeper by adding more specific object into the Watch on the same line and this will not give you the error