Gå til indhold
DokumentationPrøv Aspire
DokumentationPrøv

Compiler Error ASPIREPERSISTENCE001

Dette indhold er ikke tilgængeligt i dit sprog endnu.

Version introduced: 13.4

Resource lifetime types and members are for evaluation purposes only and are subject to change or removal in future updates. Suppress this diagnostic to proceed.

This diagnostic error is reported when a C# AppHost uses the experimental shared resource lifetime APIs. These APIs configure session, persistent, parent-process, and resource-scoped lifetimes across supported resources.

The following APIs and types are protected by this diagnostic:

  • WithSessionLifetime
  • WithPersistentLifetime
  • WithParentProcessLifetime
  • WithLifetimeOf
  • PersistenceAnnotation
  • PersistenceMode

The following code generates ASPIREPERSISTENCE001:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var worker = builder.AddExecutable("worker", "node", "../worker", "server.js")
.WithPersistentLifetime();
builder.Build().Run();

Suppress the diagnostic when you intentionally opt in to the experimental shared lifetime APIs. For container resources, you can instead use the supported container-specific WithLifetime(ContainerLifetime.Persistent) and WithLifetime(ContainerLifetime.Session) APIs.

Suppress the error with one of the following methods:

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

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

    AppHost.cs
    var builder = DistributedApplication.CreateBuilder(args);
    #pragma warning disable ASPIREPERSISTENCE001
    var worker = builder.AddExecutable("worker", "node", "../worker", "server.js")
    .WithPersistentLifetime();
    #pragma warning restore ASPIREPERSISTENCE001
    builder.Build().Run();