CS0260 Missing Partial Modifier: Causes and Fixes in C#
Last updated: October 25, 2026 · Tested with .NET 10.0.12 (SDK 10.0.401), CommunityToolkit.Mvvm 8.4.2, Microsoft.Extensions.Logging 10.0.13, Windows 11
Short answer: CS0260: Missing partial modifier on declaration of type 'X'; another partial declaration of this type exists means the compiler found two declarations of the same type and only one of them says partial. Add partial to the declaration the error points at. Most of the time you never wrote the “other” declaration: a source generator did. [GeneratedRegex], [LoggerMessage] and the MVVM Toolkit’s [ObservableProperty] all generate a partial class next to yours, and if the type is nested, every containing type needs partial too.
| You wrote | The other declaration comes from | Mark as partial |
|---|---|---|
[GeneratedRegex] method |
Regex source generator (built into .NET) | The containing class |
[LoggerMessage] method |
Logging source generator (Microsoft.Extensions.Logging) | The containing class |
[ObservableProperty] field |
CommunityToolkit.Mvvm | The view model |
| Any of the above in a nested class | The same generator | The nested class and every class around it |
A class split over two files (WinForms Form1.Designer.cs, your own split files) |
Your other file | Every declaration |
JsonSerializerContext without partial |
System.Text.Json generator | The context; this one is not CS0260, see below |
How I Tested It
One .NET 10 console project contains all six cases. Each broken version sits behind a compile symbol, so dotnet build -p:Case=REGEX builds the project with only that one mistake:
<DefineConstants>$(DefineConstants);$(Case)</DefineConstants>
#if REGEX
public static class Validators
#else
public static partial class Validators
#endif
Every error below is copied from those builds, and the fixed version was built and run at the end.
1. [GeneratedRegex] in a Class That Isn’t Partial
The regex source generator is the most common way to meet CS0260 today, because analyzers suggest it (SYSLIB1045) when you write new Regex(...) with a constant pattern. You add the attribute and a partial method, and forget the class:
public static class Validators
{
[GeneratedRegex(@"^\d{6}$")]
public static partial Regex PinCode();
}
Program.cs(34,21): error CS0260: Missing partial modifier on declaration of type 'Validators'; another partial declaration of this type exists
Note that this is the only error. The compiler doesn’t complain about the partial method or say anything about a generator, which is why the message is confusing: you can search your solution and find no other declaration of Validators. The fix:
public static partial class Validators
{
[GeneratedRegex(@"^\d{6}$")]
public static partial Regex PinCode();
}
PinCode("400001") = True
Where Is the “Other Partial Declaration”?
It is in a file the generator writes in memory during the build. To see it on disk, set EmitCompilerGeneratedFiles:
dotnet build -p:EmitCompilerGeneratedFiles=true
The files land under obj/Debug/net10.0/generated/, one folder per generator. For the regex case:
generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs
and line 5 of that file is the declaration the error talks about:
partial class Validators
In Visual Studio you can get to the same files without building to disk: Dependencies → Analyzers → (generator name) in Solution Explorer. More on how generators work in C# source generators on .NET 10.
2. [LoggerMessage] Methods
The high-performance logging pattern has the same shape: a partial method with an attribute, and a class that must be partial. With a primary constructor it looks like this:
public class OrderService(ILogger<OrderService> logger)
{
public void Ship(int orderId) => LogShipped(orderId);
[LoggerMessage(Level = LogLevel.Information, Message = "Order {OrderId} shipped")]
private partial void LogShipped(int orderId);
}
Program.cs(44,14): error CS0260: Missing partial modifier on declaration of type 'OrderService'; another partial declaration of this type exists
With public partial class OrderService(ILogger<OrderService> logger) it builds, and the generator picks up the ILogger from the primary constructor parameter on its own:
info: OrderService[809599960] Order 42 shipped
I didn’t set EventId, so the generator derived one from the method name (the generated code is new EventId(809599960, nameof(LogShipped))); set it explicitly if you filter logs by id. If you log with Serilog, the same method works through its Microsoft.Extensions.Logging provider (see the Serilog tutorial).
3. Nested Classes: Every Containing Type Must Be Partial
This is the case that still fails after you “added partial”. The inner class is partial, the outer one isn’t:
public class Outer
{
public partial class Inner
{
[GeneratedRegex(@"\d")]
public static partial Regex Digits();
}
}
Program.cs(56,14): error CS0260: Missing partial modifier on declaration of type 'Outer'; another partial declaration of this type exists
The error names Outer, not Inner. A generator can only add a member to Inner by declaring partial class Outer { partial class Inner { ... } }, so Outer gets a second declaration too. Mark the whole chain:
public partial class Outer
{
public partial class Inner
{
[GeneratedRegex(@"\d")]
public static partial Regex Digits();
}
}
Outer.Inner.Digits().Count("a1b22") = 3
4. MVVM Toolkit [ObservableProperty]
In WPF, WinUI, MAUI and Avalonia apps, CommunityToolkit.Mvvm generates the property and the change notification from a field:
public class MainViewModel : ObservableObject
{
[ObservableProperty]
private string _name = "";
}
Program.cs(69,14): error CS0260: Missing partial modifier on declaration of type 'MainViewModel'; another partial declaration of this type exists
With CommunityToolkit.Mvvm 8.4.2 that is again the only diagnostic in the build output; the toolkit doesn’t add its own hint. After public partial class MainViewModel, setting the generated Name property raises the event:
PropertyChanged: Name
5. The Classic Case: One Class in Two Files
Before generators, CS0260 mostly came from designer files. WinForms puts partial class Form1 in Form1.Designer.cs; if Form1.cs loses its partial (a bad merge, a refactoring tool, a copy-paste), you get the same error. My reproduction with two plain files:
// Invoice.cs
public class Invoice
{
public string Number { get; set; } = "";
}
// Invoice.Describe.cs
public partial class Invoice
{
public string Describe() => $"Invoice {Number}";
}
Invoice.cs(2,14): error CS0260: Missing partial modifier on declaration of type 'Invoice'; another partial declaration of this type exists
The error is reported on the declaration that is missing partial, so the file and line in the message tell you exactly what to change. All declarations need it; the access modifier only has to appear once, but if two declarations state it, they must agree.
6. System.Text.Json: Not CS0260, but the Same Mistake
If you search for CS0260 because your JSON source generation broke, you won’t find it in the build output. A JsonSerializerContext without partial gives a warning and two different errors:
[JsonSerializable(typeof(Customer))]
internal class AppJsonContext : JsonSerializerContext
{
}
Program.cs(86,16): warning SYSLIB1032: Derived 'JsonSerializerContext' type 'AppJsonContext' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1032)
Program.cs(86,16): error CS0534: 'AppJsonContext' does not implement inherited abstract member 'JsonSerializerContext.GeneratedSerializerOptions.get'
Program.cs(86,16): error CS0534: 'AppJsonContext' does not implement inherited abstract member 'JsonSerializerContext.GetTypeInfo(Type)'
Here the generator checks for partial itself and generates nothing when it’s missing, so the abstract members of JsonSerializerContext stay unimplemented. The CS0534 errors are the loud part, but the SYSLIB1032 warning above them is the real message. With internal partial class AppJsonContext:
{"Id":1,"Name":"Asha"}
For other System.Text.Json surprises, see System.Text.Json vs Newtonsoft: .NET 10 migration gotchas.
Checklist
- Open the file and line from the error; that declaration is the one missing
partial. - If the type has
[GeneratedRegex],[LoggerMessage],[ObservableProperty]or another generator attribute, the other declaration is generated, so there’s nothing else to find. - If the type is nested, add
partialto every containing type, starting from the one the error names. - For a
JsonSerializerContext, look for SYSLIB1032 rather than CS0260. - To see what a generator produced, build with
-p:EmitCompilerGeneratedFiles=trueand look inobj/.../generated/.
Microsoft’s reference for this error is errors and warnings for partial declarations, and the regex generator is documented in .NET regular expression source generators.
Related: C# source generators on .NET 10 · System.Text.Json vs Newtonsoft · Serilog in .NET · all C# tutorials
One Comment