| Severity | Error |
| Reported by | PostSharp |
| Message | The value "<Value>" of "<Expression>" is invalid. Expecting <ExpectedValues>. |
Cause
Some properties of the PostSharp compiler accept only a fixed list of values, for example DebuggerExtensionsMode, which the PostSharpDebuggerExtensionsMode MSBuild property sets. You can set these properties with MSBuild properties, as Well-Known MSBuild Properties describes, or with Property elements in postsharp.config. PostSharp reports PS0017 when it reads a property whose value is not one of the accepted values. The comparison ignores case.
<Expression>is the expression that PostSharp evaluated, such as{$DebuggerExtensionsMode}for theDebuggerExtensionsModeproperty.<Value>is the value of the expression.<ExpectedValues>lists the accepted values, separated by|, or names the expected type, such asInt32, for a property that expects a number.
When PostSharp reads the property while it initializes the project, as it does for DebuggerExtensionsMode, it also reports PS0084, which says that the project could not be initialized, and does not build the project.
In the following example, the value of DebuggerExtensionsMode is misspelled. The @Property directive of the sample sets the property as <PostSharpDebuggerExtensionsMode>Disable</PostSharpDebuggerExtensionsMode> would in a project file.
// @Property(DebuggerExtensionsMode=Disable)
// The value of DebuggerExtensionsMode is misspelled: the valid values are Disabled, Enabled and FromVisualStudioOnly.
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0017_Error;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
error PS0017: The value "Disable" of "{$DebuggerExtensionsMode}" is invalid. Expecting Enabled | Disabled | FromVisualStudioOnly.
error PS0084: The project could not be initialized because of the previous errors.
Resolution
Set the property to one of the values that the message lists. Look for the property in the project file, in the Directory.Build.props files of the source tree, and in the Property elements of the postsharp.config files of the directory of the project and of its parent directories.
In the following example, DebuggerExtensionsMode is set to Disabled.
// @Property(DebuggerExtensionsMode=Disabled)
// The value of DebuggerExtensionsMode is one of the valid values.
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0017_Fixed;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
Entering PlaceOrder.
Order placed for Coffee.
See Also
Other Resources
Well-Known MSBuild Properties
Configuring Projects Using postsharp.config
Configuration File Schema Reference