Try our conversational search powered by Generative AI!

InitializableModule in ASP.NET 4.0

Vote:
 

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?

#57669
Mar 23, 2012 13:55
Vote:
 

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

#57672
Mar 23, 2012 14:38
Vote:
 

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

#57673
Mar 23, 2012 14:38
Vote:
 

Hi Leo,

Did this work without any problems?

Sandor

#61355
Sep 17, 2012 17:31
Vote:
 

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

#63656
Nov 23, 2012 11:26
Vote:
 

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.

#63677
Nov 26, 2012 14:11
Vote:
 

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)

  • fire up Developer Command Prompt
  • run ildasm
  • open EPiServer.ApplicationModules.dll
  • dump the DLL into an IL file named EPiServer.ApplicationModules.il (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:

 

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.

 

#67830
Mar 13, 2013 13:46
Vote:
 

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.

#68023
Mar 14, 2013 17:23
Vote:
 

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

#68025
Mar 14, 2013 17:48
Vote:
 

Thanks Patrik! :)

 

#68026
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.