Compiler Error ASPIREPERSISTENCE001
Esta página aún no está disponible en tu idioma.
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:
WithSessionLifetimeWithPersistentLifetimeWithParentProcessLifetimeWithLifetimeOfPersistenceAnnotationPersistenceMode
Example
Section titled “Example”The following code generates ASPIREPERSISTENCE001:
var builder = DistributedApplication.CreateBuilder(args);
var worker = builder.AddExecutable("worker", "node", "../worker", "server.js") .WithPersistentLifetime();
builder.Build().Run();To correct this error
Section titled “To correct this error”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 = noneFor more information about editor config files, see Configuration files for code analysis rules.
-
Add the following
PropertyGroupto your project file:C# project file <PropertyGroup><NoWarn>$(NoWarn);ASPIREPERSISTENCE001</NoWarn></PropertyGroup> -
Suppress the diagnostic in code with the
#pragma warning disable ASPIREPERSISTENCE001directive:AppHost.cs var builder = DistributedApplication.CreateBuilder(args);#pragma warning disable ASPIREPERSISTENCE001var worker = builder.AddExecutable("worker", "node", "../worker", "server.js").WithPersistentLifetime();#pragma warning restore ASPIREPERSISTENCE001builder.Build().Run();