user310291
user310291

Reputation: 38180

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.

Upvotes: 50

Views: 121621

Answers (22)

Javeria
Javeria

Reputation: 17

Restart Visual Studio, it will work. If on reopening of Visual Studio you get unspecified error then delete .v11 file from your solution directory and close visual studio from task manager and then restart visual studio.

Upvotes: 0

Mohamed Ashique
Mohamed Ashique

Reputation: 1

Comment one of the crystal report version part in Webconfig in assemblies and build.

Upvotes: 0

mohammadAli
mohammadAli

Reputation: 445

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 publishing, select delete existing files prior to publish.

This will solve the issue.

Upvotes: 1

Muzammil Ahmed
Muzammil Ahmed

Reputation: 1

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.

Upvotes: 0

Eric Conklin
Eric Conklin

Reputation: 747

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.

Upvotes: 0

Tim
Tim

Reputation: 1072

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.

Upvotes: 0

Bryan Finlayson
Bryan Finlayson

Reputation: 31

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

Upvotes: 0

Arun Prasad E S
Arun Prasad E S

Reputation: 10115

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

Upvotes: 11

sojim2
sojim2

Reputation: 1307

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

enter image description here

Upvotes: 0

JonC
JonC

Reputation: 978

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.

Upvotes: 3

Simon Hawes
Simon Hawes

Reputation: 111

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.

Upvotes: 0

Mohammad Zendedel
Mohammad Zendedel

Reputation: 1

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

Upvotes: 0

Clovis Portron
Clovis Portron

Reputation: 582

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.

Upvotes: 1

Stavros
Stavros

Reputation: 6110

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

Upvotes: 14

pim
pim

Reputation: 12567

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.

Upvotes: 23

Charles
Charles

Reputation: 310

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!

Upvotes: 5

Tidy
Tidy

Reputation: 1185

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

Upvotes: 1

atbebtg
atbebtg

Reputation: 4083

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.

Upvotes: 11

groch
groch

Reputation: 3496

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.

Upvotes: 8

Adnan Ashraf
Adnan Ashraf

Reputation: 11

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

Upvotes: 1

Jack
Jack

Reputation: 25

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

Upvotes: 0

nullnvoid
nullnvoid

Reputation: 562

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

Upvotes: 40

Related Questions