Tuesday, February 7, 2012

Tuple<T1,T2> + EPiServer = Fail!

One of the dll's you need to reference in your project when using code from EPiServer Framework, for example the InitializableModule attribute, is the System.ComponentModel.Composition dll for .NET 2.0. If you do this in a .NET 4.0 project and then try to use Tuple<T1,T2> you will get an error message letting you know that Tuple<T1,T2> is declared in both System.ComponentModel.Composition.dll and mscorlib.dll. This is because System.ComponentModel.Composition declare a struct in the "System" namespace with the same name and function(?) as the new Tuple<T1,T2> struct in .NET 4.0.
To fix this problem you can add an alias to the reference of System.ComponentModel.Composition in your project, this can be done in Visual Stuio by opening the Properties window for the reference and add an alias. It can also be done in the project file with the following code,


<Reference Include="System.ComponentModel.Composition">
<HintPath>..\Solution Items\References\System.ComponentModel.Composition.dll <Aliases>episerver</Aliases>
</Reference>

After that we have "Tuple<T1,T2> + EPiServer = Success!"
As we only have the reference to this dll becuase EPiServer Framework uses it this will not have an impact on the function of EPiServer.