Diagnostic codes

Selvage includes code analysis that runs on every compilation and reports mistakes in the Console window and in your IDE. Each message links to its entry on this page. The code's first digits indicate its severity:

CodesSeverity
SLV00xxError: the code can't work.
SLV01xxWarning: the code doesn't do what it appears to.
SLV02xxHint: information, displayed in your IDE only.

Errors

SLV0001: [Inject] member must be assignable

A readonly field, a const, or a property without a setter has [Inject]. Selvage injects after the constructor, so it can't assign such a member. Make the member writable.

SLV0002: Injection context must be a reference type

A struct is passed as the context to Manual or Context. Pass an instance of a class, or typeof(T) for the static members of a class.

SLV0003: [Inject] member must be a reference type

A member whose type is a struct has [Inject]. Change its type to a class or an interface, or remove the attribute.

SLV0004: A provider overrides the wrong set of supply or teardown methods

A provider must override exactly one of Provide and ProvideAsync, and at most one of TearDown and TearDownAsync.

SLV0005: A provider names another class as itself

A registry passes another class to its base, such as class Impostor : RegistryProvider<Cheats>. Pass the class itself: RegistryProvider<Impostor>.

SLV0007: [Provide] is on a class Selvage cannot construct

The class is a Unity object, is abstract or static, or has no constructor without parameters. For more information, refer to Class requirements.

SLV0008: A preference's MemberAttribute is not an attribute class

MemberAttribute names a class that doesn't derive from System.Attribute. Name an attribute class.

Warnings

SLV0101: [Inject] and [DontInject] contradict

A member, class or assembly has both attributes. [Inject] wins. Remove [DontInject].

SLV0102: Member name matches no member

A member name passed to a Manual method doesn't exist on the context's class. Use nameof(member).

SLV0106: [Inject] member is never injected

The member's initializer assigns a value, so Selvage never injects it. Add Overwrite = true, or remove the initializer.

SLV0107: [Inject] member's type parameter may be a value type

The member's type is a type parameter that could be a struct. Add the where T : class constraint.

SLV0108: [DynamicChannel] names nothing readable

The name passed to [DynamicChannel] isn't a field or property of the class, or of a base class, readable without arguments, so the member uses its [Channel] instead. Write the name with nameof. To use a value from another class, read it through a property of this one.

Hints

SLV0208: Injected through an enclosing scope

Displays the options a member receives from the [Inject] of its class or assembly, or from the Inject by Default setting. The quick fix writes them on the member.

Unassigned field warnings

Unity and your IDE don't report CS0649, IDE0044 or, from Unity 6.5, UAC1001 on injected fields, because Selvage assigns them.

Suppress a diagnostic

To suppress a diagnostic in an assembly, add an assembly-level SuppressMessage attribute to any file of the assembly:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Selvage", "SLV0106", Justification = "...")]

Unity doesn't apply .editorconfig severities when it compiles, so they only affect your IDE.