[Experimental]
attributeWith the release of .NET 8, C# 12 introduced the [Experimental]
attribute, which provides a standardized way to mark
APIs that are still in development or experimental. This attribute is defined in the System.Diagnostics.CodeAnalysis
namespace and requires a diagnostic ID parameter used to generate compiler warnings when the experimental API
is used.
In the Dapr .NET SDK, we now use the [Experimental]
attribute instead of [Obsolete]
to mark building blocks and
components that have not yet passed the stable lifecycle certification. This approach provides a clearer distinction
between:
Experimental APIs - Features that are available but still evolving and have not yet been certified as stable according to the Dapr Component Certification Lifecycle.
Obsolete APIs - Features that are truly deprecated and will be removed in a future release.
In the Dapr .NET SDK, we apply the [Experimental]
attribute at the class level for building blocks that are still in
the Alpha or Beta stages of the Component Certification Lifecycle.
The attribute includes:
For example:
using System.Diagnostics.CodeAnalysis;
namespace Dapr.Cryptography.Encryption
{
[Experimental("DAPR_CRYPTOGRAPHY", UrlFormat = "https://docs.dapr.io/developing-applications/building-blocks/cryptography/cryptography-overview/")]
public class DaprEncryptionClient
{
// Implementation
}
}
The diagnostic IDs follow a naming convention of DAPR_[BUILDING_BLOCK_NAME]
, such as:
DAPR_CONVERSATION
- For the Conversation building blockDAPR_CRYPTOGRAPHY
- For the Cryptography building blockDAPR_JOBS
- For the Jobs building blockDAPR_DISTRIBUTEDLOCK
- For the Distributed Lock building blockWhen you use APIs marked with the [Experimental]
attribute, the compiler will generate errors.
To build your solution without marking your own code as experimental, you will need to suppress these errors. Here are
several approaches to do this:
You can use the #pragma warning
directive to suppress the warning for specific sections of code:
// Disable experimental warning
#pragma warning disable DAPR_CRYPTOGRAPHY
// Your code using the experimental API
var client = new DaprEncryptionClient();
// Re-enable the warning
#pragma warning restore DAPR_CRYPTOGRAPHY
This approach is useful when you want to suppress warnings only for specific sections of your code.
To suppress warnings for an entire project, add the following to your .csproj
file.
file.
<PropertyGroup>
<NoWarn>$(NoWarn);DAPR_CRYPTOGRAPHY</NoWarn>
</PropertyGroup>
You can include multiple diagnostic IDs separated by semicolons:
<PropertyGroup>
<NoWarn>$(NoWarn);DAPR_CONVERSATION;DAPR_JOBS;DAPR_DISTRIBUTEDLOCK;DAPR_CRYPTOGRAPHY</NoWarn>
</PropertyGroup>
This approach is particularly useful for test projects that need to use experimental APIs.
For suppressing warnings across multiple projects in a directory, add a Directory.Build.props
file:
<PropertyGroup>
<NoWarn>$(NoWarn);DAPR_CONVERSATION;DAPR_JOBS;DAPR_DISTRIBUTEDLOCK;DAPR_CRYPTOGRAPHY</NoWarn>
</PropertyGroup>
This file should be placed in the root directory of your test projects. You can learn more about using
Directory.Build.props
files in the
MSBuild documentation.
As building blocks move through the certification lifecycle and reach the “Stable” stage, the [Experimental]
attribute will be removed. No migration or code changes will be required from users when this happens, except for the removal of any warning suppressions if they were added.
Conversely, the [Obsolete]
attribute will now be reserved exclusively for APIs that are truly deprecated and scheduled for removal. When you see a method or class marked with [Obsolete]
, you should plan to migrate away from it according to the migration guidance provided in the attribute message.
In application code:
In test code:
When contributing to the SDK:
[Experimental]
for new building blocks that haven’t completed certification[Obsolete]
only for truly deprecated APIsUrlFormat
parameter