How to fix “namespace x already contains a definition for x” error? Happened after converting to VS2010

后端 未结 29 1358
深忆病人
深忆病人 2020-12-04 23:10

Specifically the error occurs in the Resources.Designer.cs:

Error 2 The namespace \'ModulusFE\' already contains a definition for \'Sto

相关标签:
29条回答
  • 2020-12-04 23:40

    This happened to me, I noticed that there was actually another class with that same name under the same namespace "OtpService.Models.Request", so all I did was to just change the namespace of the 2nd class to "OtpService.Models.Request.ExtraObj". I did this because I did not want to change the name of the conflicting class to anything else.

    0 讨论(0)
  • 2020-12-04 23:41

    Unfortunately, none of the other answers helped. My problem specifically occurred in a WPF project.

    The problem arose when I created a folder under the MainWindow folder, which effectively created a namespace something like ProjectName.MainWindow.Folder. Now, I believe because of some static designer code, Visual studio gets confused between the class MainWindow and the namespace Project.MainWindow.Folder . As a solution, I moved the Folder out of MainWindow. Looking at the Class View or the solution/project helps to recognize what namespaces and classes within them exist.

    0 讨论(0)
  • 2020-12-04 23:41

    I had a similar problem and resolved it by removing any copies/backups of the .cs file from the directory.

    0 讨论(0)
  • 2020-12-04 23:44

    This is an old question but I didn't find the fix I used, so I've added it here.

    In my case it was a namespace with the same name as a class in the parent namespace.

    To find this, I used the object browser and searched for the name of the item that was already defined.

    If it won't let you do this while you still have the error then temporarily change the name of the item it is complaining about and then find the offending item.

    0 讨论(0)
  • 2020-12-04 23:51

    I had this problem. It was due to me renaming a folder in the App_Code directory and releasing to my iis site folder. The original named folder was still present in my target directory - hence duplicate - (I don't do a full delete of target before copying) Anyway removing the old folder fixed this.

    0 讨论(0)
  • 2020-12-04 23:51

    when you have tried everything else and still get the same trouble, there is a way out; however it will be tedious and need careful preparation.

    Start another new project using existing files, or edit the project .csproj file if you are proficient in editing csproj (need backup). I will list steps for new project.

    1. preparation:
      • note all references and their sources
      • note all included files from another project
    2. rename the orginal projectname.csproj file
    3. close solution/project
    4. start new project using existing files(you will get errors from references)
    5. add back the noted references
    6. include/add existing file from other project(s)
    0 讨论(0)
提交回复
热议问题