Skip to content
Docs Try Aspire

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.

The following code generates ASPIREEXPORT005:

C# — Integration.cs
[AspireExport("addResource")]
public static IResourceBuilder<ContainerResource> AddResource(
IDistributedApplicationBuilder builder,
[AspireUnion(typeof(string))] object name) // Only 1 type specified
{
return builder.AddContainer(name.ToString()!, "myimage");
}

Either add a second type to the [AspireUnion] attribute, or remove the attribute and use the single type directly:

C# — Integration.cs
[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 with either of the following methods:

  • Set the severity of the rule in the .editorconfig file.

    .editorconfig
    [*.{cs,vb}]
    dotnet_diagnostic.ASPIREEXPORT005.severity = none

    For more information about editor config files, see Configuration files for code analysis rules.

  • Add the following PropertyGroup to your project file:

    C# project file
    <PropertyGroup>
    <NoWarn>$(NoWarn);ASPIREEXPORT005</NoWarn>
    </PropertyGroup>