Compiler Warning ASPIREEXPORT005
Version introduced: 13.2
[AspireUnion] requires at least 2 types, but {0} was specified.
This diagnostic warning is reported when an [AspireUnion] attribute is applied to a parameter with fewer than 2 types. A union type is only meaningful when it can represent two or more distinct types; using a union with a single type is equivalent to just using that type directly.
Example
The following code generates ASPIREEXPORT005:
[AspireExport("addResource")]
public static IResourceBuilder<ContainerResource> AddResource(
IDistributedApplicationBuilder builder,
[AspireUnion(typeof(string))] object name) // Only 1 type specified
{
return builder.AddContainer(name.ToString()!, "myimage");
}
To correct this warning
Either add a second type to the [AspireUnion] attribute, or remove the attribute and use the single type directly:
[AspireExport("addResource")]
public static IResourceBuilder<ContainerResource> AddResource(
IDistributedApplicationBuilder builder,
[AspireUnion(typeof(string), typeof(int))] object name)
{
return builder.AddContainer(name.ToString()!, "myimage");
}
Suppress the warning
Suppress the warning with either of the following methods:
Set the severity of the rule in the .editorconfig file.
[*.{cs,vb}] dotnet_diagnostic.ASPIREEXPORT005.severity = noneFor more information about editor config files, see Configuration files for code analysis rules.
Add the following
PropertyGroupto your project file:<PropertyGroup> <NoWarn>$(NoWarn);ASPIREEXPORT005</NoWarn> </PropertyGroup>