Try our conversational search powered by Generative AI!

InitializableModule in ASP.NET 4.0


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?

Mar 23, 2012 13:55

See this link

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

Mar 23, 2012 14:38

change the bindings to this:


   <assemblyIdentity name="System.ComponentModel.Composition" culture="neutral" />
<bindingRedirect oldVersion="2009.22.10.0" newVersion="" />

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

Mar 23, 2012 14:38

Hi Leo,

Did this work without any problems?


Sep 17, 2012 17:31

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. :)

Nov 23, 2012 11:26

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.

Nov 26, 2012 14:11

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
Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll' and
'c:\Program Files


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

 (the following underlined lines is supposed to be a bullet list... some wrinkles left to edit for the new EPiServer world forum I guess)

  • fire up Developer Command Prompt
  • run ildasm
  • open EPiServer.ApplicationModules.dll
  • dump the DLL into an IL file named (make sure all checkboxes are checked)
  • close ildasm
  • edit the IL file in the text editor of your choice
  • find the part where it declares System.ComponentModel.Composition and change it:



.assembly extern /*23000004*/ System.ComponentModel.Composition
.publickeytoken = (8F E8 3D EA 73 8B 45 B7 ) // ..=.s.E.
.ver 2009:22:10:0



.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


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.


Mar 13, 2013 13:46

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.

Mar 14, 2013 17:23

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! :)

Mar 14, 2013 17:48

Thanks Patrik! :)


Edited, Mar 14, 2013 17:52
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.