MONFY04: Type references itself
August 22, 2025 ยท View on GitHub
| Type Name | MONFY04_AttributeAnalyzer |
| Diagnostic Id | MONFY04 |
| Category | Usage |
| Severity | Warning |
| Is Enabled By Default | Yes |
Cause
The type referenced by the Monify attribute is the same as the type to which the attribute is applied.
Rule Description
A violation of this rule occurs when a type annotated with the Monify attribute references itself as the encapsulated type. This configuration attempts to encapsulate the type within itself and is not supported.
For example:
[Monify<Age>]
public partial record Age;
How to Fix Violations
Reevaluate the type referenced by the Monify attribute. If the intent is to encapsulate a different value type, update the attribute to reference that type. Otherwise, remove the attribute.
For example:
[Monify<byte>]
public partial record Age;
or alternatively:
public partial record Age;
When to Suppress Warnings
It is not recommended to suppress the rule. Instead, reconsider the usage of the Monify attribute.
If suppression is desired, one of the following approaches can be used:
#pragma warning disable MONFY04 // Type references itself
[Monify<Age>]
public partial record Age;
#pragma warning restore MONFY04 // Type references itself
or alternatively:
[Monify<Age>]
[SuppressMessage("Design", "MONFY04:Type references itself", Justification = "Explanation for suppression")]
public partial record Age;
How to Disable MONFY04
It is not recommended to disable the rule, as this may result in confusion if the expected behaviour is not observed.
# Disable MONFY04: Type references itself
[*.cs]
dotnet_diagnostic.MONFY04.severity = none