ASP.Net error: "The type 'foo' exists in both "temp1.dll" and "temp2.dll"

asp.net

asp.net Problem Overview


When running a web application project, at seemingly random times a page may fail with a CS0433 error: type exists in multiple DLL's. The DLL's are all generated DLL's residing in the "Temporary ASP.NET Files" directory.

asp.net Solutions


Solution 1 - asp.net

Add the batch="false" attribute to the "compilation" element of the web.config file.

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.

http://www.sellsbrothers.com/1995

http://support.microsoft.com/kb/919284

Solution 2 - asp.net

This might happen if you place .cs files in App_Code and changed their build action to compile in a Web Application Project.

Either have the build action for the .cs files in App_Code as Content or change the name of App_Code to something else. I changed the name since intellisense won't fix .cs files marked as content.

More info at http://vishaljoshi.blogspot.se/2009/07/appcode-folder-doesnt-work-with-web.html

Solution 3 - asp.net

One possible reason for this error is that there are 2 aspx pages which are having the same name in their inherits= in the <@page language=......inherits=> line.

Changing the inherits= name solves the error.

Solution 4 - asp.net

Just in case someone else shares my problem, I got this error when trying to publish a Web Site of a newly branched project, build worked perfectly.

Turns out I had forgotten to remove the checkbox for "Allow precompiled site to be updatable" under publish Settings -> Configure precompile.

Solution 5 - asp.net

As another data point, I just had this problem without any evidence of circular references as described in the links in Ben's answer. Building my web site project would fail with a few of these errors, and setting compilation batch="false" fixed it, but I didn't want to go that route as this is a large-ish production website.

This solution was in a subfolder of my D:\svn folder, which I had mapped to S:. When I opened the solution from S:, these errors occurred, but if I went straight to D:\svn and opened the solution, no errors.

I also noticed that, despite having compilation batch="true" in my web.config, when opening the solution from the mapped S: drive all my .ascx files get compiled into their own assemblies. If I open it from the physical location, the .ascx files get compiled into their respective folders' assemblies (which is how batch="true" is supposed to work).

Strange.

Solution 6 - asp.net

This error was due to conflict between class name of web form and wsdl stub(code behind file .cs) having the same class name i.e.

ASPX page: Dashboard Class: partiacl class Dashboard

AppCode/APIServices.cs: public partial class Dashboard

Error was reproducible only on publishing the website but build and debug did not inform any error.

Solution 7 - asp.net

In my case deleting all output assemblies from bin folders in all projects in the solution solved the issue. Unfortunately I have no explanation for it.

Solution 8 - asp.net

In my case I had renamed a project, so also the dll had been renamed. When I just copied the new dll but didn't think of deleting the old one from the server, I soon had a bunch of pairs of classes with the same names. Deleting the outdated dll's was doing the trick (of cause).

Solution 9 - asp.net

None of these answers worked for me, however I did fix the problem. Since I was using VS's Publish function to deploy the web application, I selected the option to delete all existing files prior to publish in the Publish Web wizard. This forced a clean copy of the application and everything worked fine from there.

This solution might be helpful if your local debugging copy works fine but published system isn't. Also great if you don't want to take the time to track down individual dlls to delete and don't mind the production files being deleted first.

Solution 10 - asp.net

In my case, the problem was solved when I edited a Designer.cs file that still had the duplicated class name. for some reason, when i renamed the class "logout" to "logout2", in the designer file it was not automatically changed, and was still "logout", and this class name already existed in a precompiled dll in my project (that belongs to a third party web app that I work with and develop around of).

Solution 11 - asp.net

Got this problem when put a part of an aspx page into the separate user control. On my machine everything was fine, on the server got an error.

Renamed the problem class and file.

http://support.microsoft.com/kb/919284 Method 2: Reorder the folders in the application is writing about possible circular references

Solution 12 - asp.net

None of these solutions worked for me. Both of my conflicting DLLs were in C:\...\AppData\...\Temporary ASP.NET Files\...

The problem was that I had rolled back my source repo to an earlier version - before we moved a type from one project to another project within the same solution.

I tried deleting the newer DLL - which should not have even been there at all in the older codebase - from the "Temporary ASP.NET Files" location identified by msbuild. msbuild just put it back.

I also tried the web.config setting that some here have used successfully, but that did not work either. Although, as I write this, I realize that there were actually two MVC projects within the same solution and both had errors, so the problem may have been that I did not add the setting to both.

I tried rolling my source repo forward and cleaning and rolling back again and cleaning. Nothing.

I tried deleting everything the "Temporary ASP.NET Files" location. msbuild just put it back again.

Finally, I tried rebuilding in Visual Studio. Although the command line output and the "Errors" output both gave the same msbuild "Temporary ASP.NET Files" error, the Intellisense error - when hovering over the conflicted type - actually complained about DLLs in output directories. Apparently "Clean" and "Rebuild" were not doing their jobs. I manually deleted the DLLs in the output directories identified by Intellisense, and the problem was solved.

tl;dr - Make sure you're covering all of your web.configs with the batch setting, and try to leverage Intellisense for further clues.

Solution 13 - asp.net

My problem was linked to a .dll that was getting generated in my project folder.

If you are referencing another file, instead of doing everything you see above, what fixed my problem instantly was just deleting the .dll that was staying inside my /bin directory for my project.

The problem isn't necessarily a web.config fix - it's a circular reference that needs to get resolved. I realized that I cleared the old .dll in my original project file but not in the project that was referencing it.

I don't recommend making the modification to your web.config file because that's just a band-aid fix - not really addressing the actual problem. Do that if you don't feel like fixing the problem, but if you want to avoid future headaches, just remove the .dll from both places.

Solution 14 - asp.net

I had a partial class with the same name in two different projects. I solved it by only leaving it in one project.

Solution 15 - asp.net

None of this solutions worked for me. Compiling in "Release" mode worked, but when I switched to "Debug" I got umpteen of this error Messages.

I don't understand why, but a simple restart of Visual Studio was my solution.

Solution 16 - asp.net

Sometimes it may help to remove the solution and create it again. Since this use to happen when converted from VS2005 to vs2010 some references to framework 4.0 (after upgrading ) remains in the solution, even all projects are defined as 3.5.

Normally rebuilding the solution should clear these problems.

Solution 17 - asp.net

I had the same problem when I was compiling the application on a compiling server.

My controller had a simple static code, so I changed my ascx:

 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="controllerName.ascx.cs" Inherits="Controls.controllerName" %>

To

 <%@ Control Language="C#" AutoEventWireup="true" Src="controllerName.ascx.cs" Inherits="Controls.controllerName" %>

Also removed the partial keyword from the codebehind and added a namespace to the codebehind.

This:

using System;
using System.Web.UI;

/// <summary>
/// My controller
/// </summary>
public partial class controllerName: UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}

To this:

using System;
using System.Web.UI;

namespace Controles
{
    /// <summary>
    /// My controller
    /// </summary>
    public class controllerName : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}

And that worked for me.

Solution 18 - asp.net

For me this happened when I had my PrecompiledWeb/Publish location set to the current directory which was where the site's root folder was too.

My Web Site was then seeing the publish folder as part of the project when compiling/building and then finding duplicates in that manner.

i.e. Don't put the published/precompiled version of your site in your site's code folders.

Solution 19 - asp.net

I faced with the problem in compile time.

I agree with the batch="true" attributes, error is telling there exist 2 assembly

Solution 1: deleting one of them

Solution2: Configure one of them

Solution 20 - asp.net

If the DLL's are showing in a temporary folder, you should try cleaning your solution.

Solution 21 - asp.net

Posting my solution:

The issue was related to the "On-Access Scan" of Mcafee Antivirus. Disabling this solved the problem. Somehow, the ASP Temporary folder was not being used properly by ASP when the antivirus was ON.

Hope this helps someone.

Solution 22 - asp.net

App_Code folder is causing the problem , put the class outside the folder (Works fine)

App_Code folder is not designed for Web Application Projects

http://vishaljoshi.blogspot.in/2009/07/appcode-folder-doesnt-work-with-web.html

Solution 23 - asp.net

Go to Add reference and search for both the dll, Both of the dll would have checked, uncheck one of the dll, as there are references to the same dll with different version ambiguity gets generated.

Solution 24 - asp.net

My solution was to replace CodePage="...." with CodeBehind="..." in the .aspx file. Somehow it was left as CodePage during a migration from previous .NET versions. This page directive creates another dll file which conflicts with the projects dll file.

Solution 25 - asp.net

Had a similar problem, In my case, I noticed, that cleaning a solution doesn't clear the bin folder in the visual studio. There was old compiled .dll present in the folder that is causing the issue.

Solutions:

  1. Manually delete bin folder and recompile
  2. In case of publish, select delete existing files prior to publish.

This will solve the issue.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen FultonView Question on Stackoverflow
Solution 1 - asp.netBen FultonView Answer on Stackoverflow
Solution 2 - asp.netLiljaView Answer on Stackoverflow
Solution 3 - asp.netAmrinder SinghView Answer on Stackoverflow
Solution 4 - asp.netErikDaBeView Answer on Stackoverflow
Solution 5 - asp.netMike PowellView Answer on Stackoverflow
Solution 6 - asp.netRavi GargView Answer on Stackoverflow
Solution 7 - asp.netdannydkView Answer on Stackoverflow
Solution 8 - asp.netsimagleiView Answer on Stackoverflow
Solution 9 - asp.netkad81View Answer on Stackoverflow
Solution 10 - asp.netuser960123View Answer on Stackoverflow
Solution 11 - asp.netAnastasia MelnikovaView Answer on Stackoverflow
Solution 12 - asp.netAndrew KvochickView Answer on Stackoverflow
Solution 13 - asp.netcr1ptoView Answer on Stackoverflow
Solution 14 - asp.netCosminView Answer on Stackoverflow
Solution 15 - asp.netBeeteeView Answer on Stackoverflow
Solution 16 - asp.netRoel A.K. MohunlolView Answer on Stackoverflow
Solution 17 - asp.netSalibaView Answer on Stackoverflow
Solution 18 - asp.netDavid d C e FreitasView Answer on Stackoverflow
Solution 19 - asp.netHamit YILDIRIMView Answer on Stackoverflow
Solution 20 - asp.netHugo Nava KoppView Answer on Stackoverflow
Solution 21 - asp.netAdrian NasuiView Answer on Stackoverflow
Solution 22 - asp.netArun Prasad E SView Answer on Stackoverflow
Solution 23 - asp.netRkHirparaView Answer on Stackoverflow
Solution 24 - asp.netmtkaleView Answer on Stackoverflow
Solution 25 - asp.netmohammadAliView Answer on Stackoverflow