[asp.net] Error: The type exists in both directories

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.

This question is related to asp.net asp.net-mvc

The answer is


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.


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


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.


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.


Simple Solution worked 100% for me

Put the class outside App_Code Folder

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


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


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


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!


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.


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.


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


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


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

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.


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

enter image description here


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.


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


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.


Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to asp.net-mvc

Using Lato fonts in my css (@font-face) Better solution without exluding fields from Binding Vue.js get selected option on @change You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to send json data in POST request using C# VS 2017 Metadata file '.dll could not be found The default XML namespace of the project must be the MSBuild XML namespace How to create roles in ASP.NET Core and assign them to users? The model item passed into the dictionary is of type .. but this dictionary requires a model item of type How to use npm with ASP.NET Core