Error: The type exists in both directories

前端 未结 19 1830
北恋
北恋 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:48

    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.

    0 讨论(0)
  • 2020-12-14 14:50

    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!

    0 讨论(0)
  • 2020-12-14 14:51

    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.

    0 讨论(0)
  • 2020-12-14 14:53

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

    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.

    0 讨论(0)
  • 2020-12-14 14:54

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

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