views:

78

answers:

2

Hi.

I've identified a difference of DLR between .NET 4.0 Beta 2 and the last release of .NET 4.0.

In .NET 4.0 Beta 2, this code perfectly works at runtime :

 var dateTimeList = new List<DateTime>(); 
 dynamic myDynamicObject = dateTimeList;
 object value = DateTime.Now;
 myDynamicObject.Add(value);

Now, with last release of .NET 4.0, I have an exception at run time (to solve myDynamicObject.Add(value);) :-(

In my real code, 'myDynamicObject' is a dynamic (but I know that it is always an ObservableCollection where T can be anything). 'value' is an instance which was got by some reflexions. As 'value' can have any type, the type of 'value' is Object.

Do you see how can I solve this new limitation of .NET 4.0 ?

Thanks

+1  A: 

If you change the type of value to dynamic it works fine. (assuming dateTimeList is List<DateTime>).

Brian Rasmussen
Yes you're right, it works fine !Thank you
yogi4ever
The principle here is *if a type was known at compile time then that type is used in the runtime analysis as well*. It is only expressions of dynamic type whose runtime types are used during the runtime analysis.
Eric Lippert
A: 

Ok. But why did it work with .NET 4.0 beta 2 ?

Patrice Pezillier