This project has moved. For the latest updates, please go here.

.NET4.0 And Missing System.Threading.LazyInit<T>

Jun 24, 2009 at 9:09 PM


While compiling the MEF Preview 5 source code on VS2010/.NET4.0,
I noticed a problem with System.Threading.LazyInit.

This is defined in the MEF source enclosed within #if !CLR40/#endif,
which should be defined for .NET 4.0 builds.

However, System.Threading.LazyInit does not exist in the
.NET 4.0 Framework (System.Lazy<T> does exist).

The obvious solution is to remove the #if !CLR40 (and the code
compiles and runs nicely), but the correct solution is ...?

Eamon O'Tuathail

Jun 24, 2009 at 11:33 PM
Edited Jun 24, 2009 at 11:33 PM

LazyInit<T> was renamed to Lazy<T> and moved to the System namespace.

So you can change it to use Lazy<T> instead of LazyInit<T>.  If you run into complications with this, it's fine just to remove the #if'ed code for now.  The next MEF preview will use Lazy<T>.