Open sandboxFocusImprove this doc

AR0106: Experimental Declaration Used

Severity Warning
Reported by PostSharp
Message The project <Assembly> uses <Kind> <Declaration>, which is an experimental feature and can change in a future version.

Cause

The ExperimentalAttribute constraint marks a type, a method or a field whose API is not stable yet. When PostSharp processes a project that uses the declaration from another assembly, it reports AR0106 once for each experimental declaration that the project uses. The message has no source location: it is reported on the assembly, not on the code that uses the declaration. <Assembly> is the full name of the assembly of the project. The check runs only when the using project is processed by PostSharp.

PostSharp also reports AR0106 when it processes the assembly that declares the experimental declaration, whether or not this assembly uses it. Library authors usually suppress the warning in their own assembly, as the following example does with an assembly-level SuppressWarningAttribute.

AR0106 is always a warning: ExperimentalAttribute has no severity option.

In the following example, a pricing library marks PriceCalculator.ApplyPeakPricing as [Experimental]:

using System;
using PostSharp.Constraints;
using PostSharp.Extensibility;

// PostSharp also warns the library that declares the experimental method.
[assembly: SuppressWarning( "AR0106" )]

namespace Errors.AR0106_Error.Pricing;

public static class PriceCalculator
{
    public static decimal ApplyTax( decimal price ) => price * 1.2m;

    // This method can still change or disappear in the next version of the library.
    [Experimental]
    public static decimal ApplyPeakPricing( decimal price, int hour ) => hour is >= 17 and < 20 ? price * 1.1m : price;
}

The application, in another assembly, calls ApplyPeakPricing:

using System;
using Errors.AR0106_Error.Pricing;

namespace Errors.AR0106_Error;

public class CheckoutService
{
    public decimal GetPrice( decimal price, int hour )
    {
        // This line uses PriceCalculator.ApplyPeakPricing, an experimental method of the pricing library.
        return PriceCalculator.ApplyTax( PriceCalculator.ApplyPeakPricing( price, hour ) );
    }
}

public static class Program
{
    public static void Main()
    {
        Console.WriteLine( $"Price: {new CheckoutService().GetPrice( 100m, 18 ):0.00}" );
    }
}
warning AR0106: The project AR0106_Error, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null uses method Errors.AR0106_Error.Pricing.PriceCalculator.ApplyPeakPricing, which is an experimental feature and can change in a future version.

Resolution

  • Use the stable API of the library instead of the experimental declaration.
  • When you accept that the declaration can change, suppress the warning for the whole project with [assembly: SuppressWarning( "AR0106" )], or add AR0106 to the PostSharpDisabledMessages property of the project.

In the following example, the application uses only PriceCalculator.ApplyTax.

using System;
using Errors.AR0106_Fixed.Pricing;

namespace Errors.AR0106_Fixed;

public class CheckoutService
{
    public decimal GetPrice( decimal price, int hour )
    {
        // This line uses only the stable methods of the pricing library.
        return PriceCalculator.ApplyTax( price );
    }
}

public static class Program
{
    public static void Main()
    {
        Console.WriteLine( $"Price: {new CheckoutService().GetPrice( 100m, 18 ):0.00}" );
    }
}
Price: 120.00

See Also

Reference

ExperimentalAttribute
SuppressWarningAttribute

Other Resources

Validating Architecture