48
votes

In a MVC2 project I moved a file from App_code to Content folder and compiled it. Then move it back again to App_Code and then changed its Build Action to "Compile". Now I get this error and I don't know how to fix this to make my program work again:

CS0433: The type 'Helper' exists in both 'c:\Users...\AppData\Local\Temp\Temporary ASP.NET Files\root\b00d4b7d\b2553f9c\App_Code.zowyklar.dll' and 'c:\Users...\AppData\Local\Temp\Temporary ASP.NET Files\root\b00d4b7d\b2553f9c\assembly\dl3\5c6d3537\19f85663_cde9cb01\MyProject.DLL'

Cleaning and Rebuilding doesn't solve the problem.

19
I had something similar, this time it was a .NET DLL (system.web.something) that was copied inappropriatedly to the project bin dir. Removing it from the bin directory solved the issue.Rob
I'm getting this error a lot, but for me clean&rebuild fixes it. For up to fifteen minutes.Paul Kienitz

19 Answers

40
votes

This has been answered in a separate question and resolved the problem for me. Be sure to vote up the original person's answer.

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

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/news/showTopic.aspx?ixTopic=1995

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

23
votes

Assuming you're building a Web Application, which it appears you are given the MVC2 point, you shouldn't use the App_Code folder. It was not designed to be integrated with Web Application projects.

When you Compile in Visual Studio, all the code in your application (including in App_Code) gets compiled into an assembly. When you run your application, asp.net knows about a "special" folder called App_Code and compiles the content of it into an assembly with a unique name. Thus, anytime you run the project you'll run into this problem.

The solution:

Rename your App_Code folder to something like "Code" or "Global" (and update your now broken references) & voila, problem solved.

12
votes

My issue was with different version of DevExpress.
Deleting all contents from bin and obj folders made my website run again...

Reference: https://www.devexpress.com/Support/Center/Question/Details/KA18674

11
votes

Try cleaning your solution and then try to rebuild. Visual Studio probably still has reference to the old dll after it created the new dll.

11
votes
8
votes

I had the same error : The type 'MyCustomDerivedFactory' exists in both and My ServiceHost and ServiceHostFactory derived classes where in the App_Code folder of my WCF service project. Adding

<configuration>
  <system.web>
    <compilation batch="false" />
  </system.web>
<configuration>

didn't solve the error but moving my ServiceHost and ServiceHostFactory derived classes in a separate Class library project did it.

5
votes

TRY THIS ONE!

Normally, when this happen locally, i clean all the aspnet temp folder. But recently it was happing when i published my website in Azure. So "clean temp aspnet folder" was not a solution.

After searching on the internet, i founded this:

Clear Temp ASP.NET files from Azure Web Site

It works for me!

2
votes

The App_Code folder isn't intended to be used with MVC Projects (WAP).

Files in the App_Code folder gets compiled automatically as part of a special dll. If the Build Action property on the file is set to Compile, the same class will also get compiled as part of the main dll and you will end up with two copies.

Setting the Build Action property to None makes sure there is only one copy of the class in the project. The compiler will not catch any errors in the App_Code folder when building but Intellisense will still validate the code but compile-time errors won't show up until it is compiled on-the-fly.

The recommended solution is to put code in a normal folder and make sure the Build Action is set to Compile.

1
votes

There might be two classes with same name "Helper" in your solution/project. Change name of one of them and then rebuild

1
votes

I had the same problem in one of my projects. Turns out the problem started from me coping a Master page.

The problem will also occur if two pages "Inherit" the same page.

I had the following line of code at the top of my "LoginMaster.Master" & "MasterPage.Master"

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MainMaster.master.cs" Inherits="Master_Pages_Header" %>

I changed the Inherits on my "LoginMaster.Master to:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="LoginMaster.master.cs" Inherits="Master_Pages_LoginMaster" %>

I was immediately able to publish my project with out any problems. Hopefully this works for someone else. I apologize for not use the correct terms.

You will also need to change the class in the .cs to match the Inherits name. If you don't it will cause an error.

IE:

public partial class Master_Pages_LoginMaster : System.Web.UI.MasterPage
1
votes

If your are migrating ASP.NET 2.0 Website to .NET Web APP 4.5, you can have that issue too. And puting batch=false, adding a namespace etc... can not work.

The workaround is to rename the old App_Code folder (or any problematic folder) to Old_App_Code (like the automatic process do it), or any other name.

0
votes

In the Web Application(not Web Site), I change App_Code*.cs Build Action(file properties) from Compile to Content. then the problem solve.

0
votes

In my case, I have to items with same name but different extensions in my project. One was accountRep.aspx and the other accountRep.rpt made by Crystal Report. Problem solved when I changed accountRep.rpt to accountReport.rpt

0
votes

Another potential solution which worked for me was to change all references from

CodeFile="~/..."

to

CodeBehind="~/..."

in all .master and .aspx pages

This occurred when converting an old website to a proper web application with a solution file.

I didn't find this information anywhere else so hope this helps someone.

0
votes

I fixed this by checking Delete all existing files prior to publish in Visual Studio:

enter image description here

0
votes

In my case I got this error when I had mistakenly named a class the same as the class it was inheriting from.

0
votes

I tried pretty much every suggestion on this page, but had to delete visual studio 2017 completely off my machine. I reinstalled the latest version (2019) and it magically worked. I hope this helps someone in the future.

0
votes

I fixed this by removing one of the unneeded NuGet packaged referenced in the dll files causing this conflict.

So in this case I had both ZXing.Net and ZXing.Net.Mobile installed. Since I was creating a mobile app in Xamarin Forms, removing the ZXing.Net NuGet package resolved this.

Be sure to check and make sure you don't have redundant NuGet packages for different frameworks, i.e. ASP.Net versus Xamarin.

0
votes

Try to change folder name

  • from APP_CODE
  • to CODE.

This fixed my issue.

Alternatively you can move to another folder all your code files.