| Severity | Warning |
| Reported by | Metalama.Framework (Roslyn analyzer) |
| Message | The name '<TypeName>', declared in <ItemName>, matches no type in this compilation. A generic type must be written with its arity, as in System.Collections.Immutable.ImmutableArray`1. |
Cause
Aspects, fabrics, validators, and the types that you mark with the [ImmutableType] attribute must be written in an immutable style (see LAMA0882). A type that isn't marked with [ImmutableType] and that the analyzer doesn't know is considered mutable. A project can change this verdict for types that it doesn't own by declaring them in its project file:
MetalamaImmutableTypeitems name types that are immutable.MetalamaImmutableContractTypeitems name base types or interfaces whose implementations must be immutable, as if they were marked with[ImmutableType].
Each item contains the full metadata name of a type, without the assembly name. A mistyped name would silently turn the declaration into one that never applies, which defeats its purpose. For this reason, the analyzer reports LAMA0885 at the end of the compilation for each declared name that matches no type. In the message, <TypeName> is the name as declared, and <ItemName> is the item that declares it, MetalamaImmutableType or MetalamaImmutableContractType. The diagnostic has no source location because it concerns the project file.
The usual causes are:
- a typo in the namespace or in the type name;
- a generic type written without its arity: the metadata name of
ImmutableArray<T>isSystem.Collections.Immutable.ImmutableArray`1, with a backtick and the number of type parameters; - a nested type written with a dot instead of a plus sign, as in
Outer+Inner; - a type that the project no longer references, for instance after removing a package.
The analyzer checks only the names that you declare. It doesn't check its own built-in list.
This diagnostic is reported by a Roslyn analyzer from the configuration of the project file, which the snapshot tests of this documentation don't reproduce, so it can't be shown in an example.
Resolution
Correct the name in the project file. The following example declares a type, and a generic type with two type parameters, using its arity:
<ItemGroup>
<MetalamaImmutableType Include="Contoso.Money" />
<MetalamaImmutableType Include="Contoso.Pair`2" />
</ItemGroup>
If the project no longer uses the type, remove the item.