Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing partial modifier on declaration of type [class name]; another partial declaration of this type exists

Tags:

c#

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...
    }
}
like image 375
Zignd Avatar asked Apr 15 '14 21:04

Zignd


2 Answers

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

like image 51
Ulugbek Umirov Avatar answered Nov 15 '22 10:11

Ulugbek Umirov


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.

like image 26
Reed Copsey Avatar answered Nov 15 '22 10:11

Reed Copsey