Compiler error: Global.asax exists multiple times

I have experienced yet another really strange and annoying problem. This happened in an Umbraco-project that I’m working with. The error message you can see...

  • Gustaf Lindqvist
  • 28 January 2011
  • 0

I have experienced yet another really strange and annoying problem. This happened in an Umbraco-project that I’m working with. Below I tried to print out the the error message, the cause of the error and a few suggestions of a solution.

Error message

Server error in an application/.
Kompilatorfel   
Beskrivning: Ett fel uppstod vid kompilering av en resurs som är nödvändig för att utföra den aktuella begäran. Granska den specifika felinformationen nedan och gör nödvändiga ändringar i källkoden.    
Kompilatorfelmeddelande: CS0433: The type 'ASP.global_asax' exists in both 'c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\b07a9acf\ecbffce5\App_global.asax.aeaktxnn.dll' and 
'c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\b07a9acf\ecbffce5\assembly\dl3\45882db2\1f60d813_3aaccb01\App_global.asax.DLL'   
Källfel:   
Rad 129:        }   
Rad 130:           
Rad 131:        protected ASP.global_asax ApplicationInstance {  
Rad 132:            get {  
Rad 133:                return ((ASP.global_asax)(this.Context.ApplicationInstance));  
Källfil: c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\b07a9acf\ecbffce5\App_Web_default.aspx.cdcab7d2.f79pmd-5.0.cs    

Cause of the problem are these files

I have noticed that two files are created in the bin-folder called:

  • App_Browsers.dll
  • App_global.asax.dll

image

Especially the App_global.asax.dll is causing the double existence error since the global.asax file will also be built on run time. That is what is causing the exception, so make sure that you have removed this.

Well, how to solve it!

This shouldn’t happen normally of course, but it seems to be related to the fact that I have upgraded to be using VS 2010. Some seems to state that this is due to the fact that even though I have set the application to be compiled with .Net 2.0 it seems to be using .Net 4.0 and therefore creating these files.

Other solutions I haven’t found, any ideas, put them in the comments?

Argument for using an own Global.asax file

Normally it is not recommended to use an own Global.asax file in an Umbraco project since it alread exists in the Umbraco.Presentation project. The main requirement for using your own is to inherit from umbraco.Global.

Recommended is to rather use HttpModules instead, which is a valid argument. We are using PartialCaching in this project, so we needed a way to empty or differentiate the cache based on different nodes. Therefore we put that in the Global.asax. Maybe we should move it!