5

Note: I found some similar questions (Link 1 and Link 2), but they didn't helped me.

I'm trying to create a partial class, but I getting the following error on the "main class":

Missing partial modifier on declaration of type SomeClass; another partial declaration of this type exists

Those are the files that cotains the classes and the problem is that the error is pointing to the "main class" not the partial class. The reason for that I'm creating this partial class is that the file SomeClass.cs is Checked Out with someone else as we (the people developing with me) are using Team Foundation Server for source control.

File: SomeClass.cs

namespace MyNamespace
{
    public class SomeClass
    {
        // Some methods...
    }
}

File: SomeClass2.cs

namespace MyNamespace
{
    public partial class SomeClass
    {
        // Some methods...
    }
}
Community
  • 1
  • 1
Zignd
  • 6,246
  • 11
  • 34
  • 57

3 Answers3

5

If you check MSDN - Partial Classes and Methods you can find the notice: All the parts must use the partial keyword.

Ulugbek Umirov
  • 12,231
  • 2
  • 20
  • 29
4

Just flag both declarations as partial.

There is no "main" class and "partial" classes when you use partial in C#. The partial modifier just means that the class can be defined in multiple locations, but it is still a single class. The compiler wants all declarations of the class to be denoted as partial if any are partial, which has the effect of always making every location obvious that there is more to the class declaration than what you see at the time.

Reed Copsey
  • 522,342
  • 70
  • 1,092
  • 1,340
1

If any declaration of a class is labeled partial, then all declarations of it need to be partial.

musical_coder
  • 3,870
  • 3
  • 13
  • 18