Skip to main content

Analyzer diagnostics

Mapperly emits several diagnostics:

Rule IDSeverityDescription
RMG001ErrorA mapping method has an unsupported signature.
RMG002ErrorNo accessible parameterless constructor found.
RMG003WarningNo overlapping enum members found.
RMG004WarningIgnored target member not found.
RMG005ErrorMapping target member not found.
RMG006ErrorMapping source member not found.
RMG007ErrorCould not map member.
RMG008ErrorCould not create mapping.
RMG009InfoCannot map to read only member.
RMG010InfoCannot map from write only member.
RMG011InfoCannot map to write only member path.
RMG012WarningSource member was not found for target member
RMG013ErrorNo accessible constructor with mappable arguments found
RMG014WarningCannot map to the configured constructor to be used by Mapperly
RMG015InfoCannot map to init only member path
RMG016ErrorInit only member cannot handle target paths
RMG020WarningSource member is not mapped to any target member
RMG021WarningIgnored source member not found
RMG022ErrorInvalid object factory signature
RMG023ErrorMapping source member for a required target member not found
RMG024ErrorThe reference handler parameter is not of the correct type
RMG025ErrorTo use reference handling it needs to be enabled on the mapper attribute
RMG029ErrorQueryable projection mappings do not support reference handling
RMG030ErrorReference loop detected while mapping to an init only member
RMG031WarningReference loop detected while mapping to a constructor member
RMG032WarningThe enum mapping strategy ByName cannot be used in projection mappings
RMG033InfoObject mapped to another object without deep clone
RMG034ErrorDerived source type is specified multiple times, a source type may only be specified once
RMG035ErrorDerived source type is not assignable to parameter type
RMG036ErrorDerived target type is not assignable to return type
RMG037WarningAn enum member could not be found on the source enum
RMG038WarningAn enum member could not be found on the target enum
RMG039ErrorEnum source value is specified multiple times, a source enum value may only be specified once
RMG040ErrorA target enum member value does not match the target enum type
RMG041ErrorA source enum member value does not match the source enum type
RMG042ErrorThe type of the enum fallback value does not match the target enum type
RMG043WarningEnum fallback values are only supported for the ByName and ByValueCheckDefined strategies, but not for the ByValue strategy
RMG044WarningAn ignored enum member can not be found on the source enum
RMG045WarningAn ignored enum member can not be found on the target enum
RMG046ErrorThe used C# language version is not supported by Mapperly, Mapperly requires at least C# 9.0
RMG047ErrorCannot map to member path due to modifying a temporary value, see CS1612
RMG048ErrorUsed mapper members cannot be nullable
RMG049WarningSource member is ignored and also explicitly mapped
RMG050WarningTarget member is ignored and also explicitly mapped
RMG051WarningInvalid ignore source member found, nested ignores are not supported
RMG052WarningInvalid ignore target member found, nested ignores are not supported
RMG053ErrorThe flag MemberVisibility.Accessible cannot be disabled, this feature requires .NET 8.0 or greater
RMG054ErrorMapper class containing 'static partial' method must not have any instance methods
RMG055ErrorThe source type does not implement ToString with the provided formatting parameters, string format and format provider cannot be applied
RMG056ErrorInvalid format provider signature
RMG057ErrorFormat provider not found
RMG058ErrorMultiple default format providers found, only one is allowed
RMG059ErrorMultiple default user mappings found, only one is allowed
RMG060WarningMultiple user mappings discovered without specifying an explicit default
RMG061ErrorThe referenced mapping was not found
RMG062ErrorThe referenced mapping name is ambiguous
RMG063ErrorCannot configure an enum mapping on a non-enum mapping
RMG064ErrorCannot configure an object mapping on a non-object mapping
RMG065WarningCannot configure an object mapping on a queryable projection mapping, apply the configurations to an object mapping method instead
RMG066WarningNo members are mapped in an object mapping
RMG067ErrorInvalid usage of the MapPropertyAttribute
RMG068InfoCannot inline user implemented queryable expression mapping
RMG069WarningRuntime target type or generic type mapping does not match any mappings
RMG070ErrorMapping nested member not found
RMG071WarningNested properties mapping is not used
RMG072WarningThe source type of the referenced mapping does not match
RMG073WarningThe target type of the referenced mapping does not match
RMG074ErrorMultiple mappings are configured for the same target member
RMG075ErrorInvalid usage of the MapValueAttribute
RMG076WarningCannot assign null to non-nullable member
RMG077ErrorCannot assign constant value because the type of the value does not match the type of the target
RMG078ErrorCannot assign method return type because the type of the value does not match the type of the target
RMG079ErrorThe referenced method could not be found or has an unsupported signature
RMG080ErrorThe MapValueAttribute does not support types and arrays
RMG081ErrorA mapping method with additional parameters cannot be a default mapping
RMG082WarningAn additional mapping method parameter is not mapped
RMG083InfoCannot map to read only type
RMG084ErrorMultiple mappings are configured for the same source string
RMG085ErrorInvalid usage of fallback value
RMG086ErrorThe source of the explicit mapping from a string to an enum is not of type string
RMG087ErrorThe target of the explicit mapping from an enum to a string is not of type string
RMG088InfoThe attribute to build the name of the enum member is missing
info

Mapperly only emits updated source code on build. You won't see the updated mapper code or mapper diagnostics until you perform a build.

This is done for performance reasons, otherwise the IDE could become laggy.

Editorconfig

The severity of these diagnostics can be customized via an .editorconfig file:

.editorconfig
[*.cs]
dotnet_diagnostic.{RuleID}.severity = error
dotnet_diagnostic.RMG020.severity = error

See also code analysis configurations and available severity levels.

Suppress diagnostics

See the Microsoft documentation on how to suppress diagnostics in C# here. In summary, you can use one of the following approaches:

  • Use the .editorconfig file (for an entire file, directory or project, depending on the editorconfig scope)
    dotnet_diagnostic.RMG066.severity = none
  • Use the SuppressMessageAttribute (for a method)
    [SuppressMessage("Mapper", "RMG066:No members are mapped in an object mapping")]
  • Use precompiler directives (for specific lines of code)
    #pragma warning disable RMG066 // No members are mapped in an object mapping
    #pragma warning restore RMG066 // No members are mapped in an object mapping