See this link http://world.episerver.com/Articles/Items/EPiServer-CMS-60-now-supporting-ASPNET-40/
I've got the same error before and the trick in my case was to edit the project file with notepad as the above link suggested
change the bindings to this:
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Composition" culture="neutral" />
<bindingRedirect oldVersion="2009.22.10.0" newVersion="4.0.0.0" />
</dependentAssembly>
Remove the epi-"System.ComponentModel.Composition.dll" from project references and remove it from the bin folder. Then reference the native .net 4 composition.dll
I can't get this to work. Changing the web.config and reference as Leo suggests causes a whole lot of compile-time errors. And all I wanted to do was to do a nice implementation of Singleton pattern... I guess I have to use the old and ugly if-lock-if version instead. :)
What Leo said should work. It works for me at least :)
What may be an issue is of you've used ModuleDependencyAttribute or InitializableModuleAttribute. To get around this i create my modules in their own class libraries which references EPiserver's System.ComponentModle.Composition.dll.
Similar situation here, trying to use VisitorGroups. In order to use that, I have to reference EPiServer.ApplicationModules.dll
This brings me to my first compile time error:
Error 1 The type 'System.ComponentModel.Composition.ExportAttribute'
is defined in an assembly that is not referenced. You must add a
reference to assembly 'System.ComponentModel.Composition,
Version=2009.22.10.0, Culture=neutral,
PublicKeyToken=8fe83dea738b45b7'. C:\project\branches\development\Dependencies\EPiServer.ApplicationModules.dll
I'm stressing that this is a compile time error, so the app.config bindingRedirect is inapplicable here.
To reference that specific version I have to indeed modify my CSPROJ manually as Hao Peng says, which brings me to my second compile time error:
Error 7 The type 'System.Lazy<T>' exists in both 'c:\Program Files
(x86)\Reference
Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll' and
'c:\Program Files
(x86)\EPiServer\Framework\6.2.267.1\bin\System.ComponentModel.Composition.dll'
So that's not going to work either.
I made a fix by myself, but it is probably controversial to say the least: I modified EPiServer.ApplicationModules.dll manually to point to System.ComponentModel.Composition version 4.0.0.0...
(the following underlined lines is supposed to be a bullet list... some wrinkles left to edit for the new EPiServer world forum I guess)
from:
.assembly extern /*23000004*/ System.ComponentModel.Composition
{
.publickeytoken = (8F E8 3D EA 73 8B 45 B7 ) // ..=.s.E.
.ver 2009:22:10:0
}
into:
.assembly extern /*23000004*/ System.ComponentModel.Composition
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // ..=.s.E.
.ver 4:0:0:0
}
Final step, in the command prompt window, run ilasm /DLL EPiServer.ApplicationModules.il
congratulations, you now have a DLL that works in .NET 4...
I also had to reference System.Web.Abstractions in my project and finally my visitor groups worked.
I have adviced my client to take it up with EPiServer support instead of using this fix... but it's interesting to see it working.
Alright... EPiServer helped us out and we managed to get it working! The trick is a feature called Extern aliases. I had never used it before (hopefully I won't have to use it ever again).
Some links for more information about this: a discussion in stackoverflow and a walkthrough in MSDN.
In short, you reference all the necessary assemblies. You make sure the System.ComponentModel.Composition is that version that ships with EPiServer 6 R2 (2009.22.10.0). And in the properties of the reference, there's the Aliases property. By default it's global. Change it for this assembly into something else, e.g. Legacy.
This way, the System.Lazy type of that assembly goes out of the implicit global:: scope and gets hidden away into the Legacy:: scope, and everything can compile again.
Wow, awesome! Works for me too! :)
Thank you for digging deeper into this problem, and also for writing such clear instructions! If this was Stack Overflow, I would upvote your answer! :)
I am trying to create a [InitializableModule] class. To make this work, i need a reference to the System.ComponentModel.Composition.dll that EPiServer provides (NOT the one that comes with the .NET Framework). So I reference the one from the EPiServer/framework/bin folder. However, now I get the error:
Error 102
The type 'System.Lazy<T>' exists in both 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll' and 'c:\Program Files x86)\EPiServer\Framework\6.0.318.113\bin\System.ComponentModel.Composition.dll'
C:\Projects\EpiServer Shared Platform\Cms\branches\development\ESP.Core\Providers\DefaultGlobals.cs
There is a duplicate declaration between the ComponentModel.Compositions from EPiServer and MS Framework 4.0.
I tried both the 6.0 and 6.1 versions for the EPiServer System.ComponentModel.Compositions dll.
Is there a solution for this problem?