Microsoft.VisualStudio.Composition.Analyzers

June 19, 2026 ยท View on GitHub

Analyzers for MEF consumers to help identify common errors in MEF parts.

Analyzer IDDescription
VSMEF001Ensures that importing properties define a set accessor.
VSMEF002Detects mixing of MEF v1 and MEF v2 attributes on the same type.
VSMEF003Ensures that exported types are implemented by the exporting class.
VSMEF004Ensures exported types have a parameterless constructor or importing constructor.
VSMEF005Detects multiple constructors marked with [ImportingConstructor].
VSMEF006Ensures import nullability matches AllowDefault setting.
VSMEF007Detects when a type imports the same contract multiple times.
VSMEF008Warns when an import contract type is not assignable to the importing member type.
VSMEF009Ensures [ImportMany] members use supported collection shapes and can be initialized correctly.
VSMEF010Ensures constructor-parameter [ImportMany] imports use supported collection types.
VSMEF011Detects members annotated with both [Import] and [ImportMany].
VSMEF012Warns when a disallowed MEF attribute version is used.
VSMEF015Warns when a same-compilation metadata view interface could be source-generated but is not annotated for generation.
VSMEF016Warns when a referenced metadata view interface should be recompiled with [MetadataView].
VSMEF017Reports invalid [MetadataView] usage on interfaces that cannot be source-generated.

Diagnostic Suppressors

Suppressor IDSuppressed DiagnosticDescription
VSMEF013IDE0044Suppresses "Make field readonly" for fields decorated with MEF [Import] or [ImportMany] attributes, since such fields are assigned at runtime via reflection.
VSMEF014CS8618Suppresses "Non-nullable member must contain a non-null value when exiting constructor" for MEF importing members that are initialized after construction unless AllowDefault = true is specified.
VSMEF018CS0649Suppresses "Field is never assigned to, and will always have its default value" for MEF imported fields on exported parts, since composition assigns them at runtime.