Aspire

Compiler Warning ASPIRECOMPUTE002

Version introduced: 13.0

Kubernetes persistent volume APIs are for evaluation purposes only and are subject to change or removal in future updates. Suppress this diagnostic to proceed.

This diagnostic warning is reported when using the experimental Kubernetes persistent volume APIs: KubernetesPersistentVolumeExtensions, KubernetesPersistentVolumeResource, PersistentVolumeAccessMode, and AzureKubernetesPersistentVolumeExtensions.

GetHostAddressExpression returns a ReferenceExpression for the host only, without scheme, port, or path. It isn’t a full URL. GetEndpointPropertyExpression composes the host, scheme, and port expressions by default, and compute environments can override it with platform-specific mappings.

The default GetHostAddressExpression implementation throws NotImplementedException, so environments that don’t provide host mapping (for example, AzureKubernetesEnvironmentResource) still inherit that behavior.

No suppression required
var builder = DistributedApplication.CreateBuilder(args);
var environment = builder.AddDockerComposeEnvironment("env");
var api = builder.AddContainer("api", "nginx")
.WithHttpEndpoint(targetPort: 80);
IComputeEnvironmentResource compute = environment.Resource;
var endpoint = api.GetEndpoint("http");
ReferenceExpression host = compute.GetHostAddressExpression(endpoint);
ReferenceExpression url = compute.GetEndpointPropertyExpression(
endpoint.Property(EndpointProperty.Url));

Suppress the warning with either of the following methods:

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

    .editorconfig
    [*.{cs,vb}]
    dotnet_diagnostic.ASPIRECOMPUTE002.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);ASPIRECOMPUTE002</NoWarn>
    </PropertyGroup>
  • Suppress in code with the #pragma warning disable ASPIRECOMPUTE002 directive:

    Suppressing the warning
    #pragma warning disable ASPIRECOMPUTE002
    var k8s = builder.AddKubernetesEnvironment("k8s");
    var data = k8s.AddPersistentVolume("data")
    .WithAccessMode(PersistentVolumeAccessMode.ReadWriteOnce);
    #pragma warning restore ASPIRECOMPUTE002