Error: The type exists in both directories

前端 未结 19 1961
北恋
北恋 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 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.

提交回复
热议问题