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

后端 未结 29 1362
深忆病人
深忆病人 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:53

    The way I solved it was to remove all of the enums from the model browser, and then re-add them again. Somehow miraculously the tool regenerated everything perfectly and the error message went away (I'm using VS2012, FYI).

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

    This is not the best solve, but if you really don't care it is an easy solution. I simply renamed my class. So I had class Card and I changed it to MyCard.

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

    I think this issue is because you have added for a single table, 2 DAL classes. If this table is included in a relation, then remove the table_name.dbml for it, and keep that for the related tables. You must use one of them.

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

    I came across this partial class problem in a winform of a solution after converting from .net 4.5.1 to 4.7.2.

    Initially the problem the compiler was not complaining about partial class but the use of properties.default...without qualification. After adding Global::solnNameSpace. qualifiers, then I got the partial class problem.

    after viewing answers in this thread, I look at the resource designer file, I found it was generated with explicit solnNameSpace while the classes in the solution did not. Also the solnNameSpace is the same as the name of the problematic class name.

    To fix the problem with the least effort and time I backed out Global... qualifier and removed the explicit namespace ... and end statements from the resource designer file. I know I may get in trouble later on if there were changes that cause auto generation of the resource designer file but I was was under tight deadline. I made documentation on the temp change instead of a better long term solution since the solution is under no change allowed for nature of the solution and multi project use.

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

    I had the same issue just now, and I found it to be one of the simplest of oversights. I was building classes, copying and pasting code from one class file to the others. When I changed the name of the class in, say Class2, for example, there was a dropdown next to the class name asking if I wanted to change all references to Class2, which, when I selected 'yes', it in turn changed Class1's name to Class2.

    Like I said, this is a very simple oversight that had me scratching my head for a short while, but double check your other files, especially the source file you copied from to ensure that VS didn't change the name on you, behind the scenes.

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

    I had something similar to this happen in my WPF application. It arose when I was trying to do some cleanup by declaring a namespace that was more descriptive. The problem arose because I had named the namespace in the code-behind (or cs) the same as the Window class. The namespace in the code-behind should have the last section stripped (after the rightmost dot) and used to declare the class and instantiate it. Notice Win below:

    xaml

    <Window x:Class="FrameApp.UI.Invoice.Win" ...>

    code-behind

    namespace FrameApp.UI.Invoice
    {
        public partial class Win : Window
        {
            public Win()
        }
    }
    

    An obvious oversight but it set me back at least an hour with all the errors that appeared.

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