Error: The type exists in both directories

前端 未结 19 1828
北恋
北恋 2020-12-14 14:13

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

相关标签:
19条回答
  • 2020-12-14 14:56

    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 讨论(0)
  • 2020-12-14 14:59

    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.

    0 讨论(0)
  • 2020-12-14 15:00

    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

    0 讨论(0)
  • 2020-12-14 15:00

    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 讨论(0)
  • 2020-12-14 15:01

    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
    
    0 讨论(0)
  • 2020-12-14 15:04

    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.

    0 讨论(0)
提交回复
热议问题