Monday, 3 March 2014

ASP.NET - The type exists in both temp123.dll and temp456.dll

ASP.Net error: The type 'abc' exists in both "temp123.dll" and "temp456.dll

This is a common issue occuring in ASP.NET Web Application Projects. This is an age old issue in ASP.NET. At random, the pages gives error CS0433, saying the type exists in multiple DLLs.
These dlls are generated and located in "Temporary ASP.NET Files" directory. The error occurs most in pages using user controls.

A sample of this error is as below:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0433: The type 'myusercontrol_ascx' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\sb2\4d76034e\bec2c8d0\App_Web_myusercontrol.ascx.abcd7d2.zyxwv5k.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\sb2\4d76034e\zyxwv0\App_Web_abcde.dll'


Solution
In the "compilation" element of web.config file, add the attribute "batch" and set its value to "false"
<configuration ...>
  <system.web>
    <compilation ... batch="false"/>


This problem occurs because of the way in which ASP.NET 2.0 uses the application references and the folder structure of the application to compile the application. If the batch property of the element in the web.config file for the application is set to true, ASP.NET 2.0 compiles each folder in the application into a separate assembly.

No comments:

Post a Comment