| Severity | Warning |
| Reported by | PostSharp |
| Message | No IDebuggerAspectEnhancer is available for "<Type>". RequiresDebuggerEnhancementAttribute will be ignored. |
Cause
PostSharp marks the code of its advices and aspects so that the debugger steps over the code that PostSharp generates. It does so with RequiresDebuggerEnhancementAttribute, an attribute of the PostSharp.Aspects.Internals namespace that the advice and aspect types of PostSharp carry. The attribute is internal to PostSharp: it is public only for technical reasons and is not part of the documented API.
When this attribute is applied to a type, PostSharp looks for a debugger enhancer that supports the type. Only the types of PostSharp and of its plug-ins have one. For any other type, PostSharp reports LA0161 on the type and ignores the attribute. The build goes on, and the program runs as without the attribute.
In the following example, a helper class of a logging aspect has the attribute.
using System;
using PostSharp.Aspects;
using PostSharp.Aspects.Internals;
using PostSharp.Serialization;
namespace Errors.LA0161_Error;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
LogWriter.Write( $"Entering {args.Method.Name}" );
}
}
// This internal attribute of PostSharp is meant for the advice types of PostSharp, not for a class of your own.
[RequiresDebuggerEnhancement( DebuggerStepOverAspectBehavior.StepOut )]
public static class LogWriter
{
public static void Write( string text ) => Console.WriteLine( text );
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Ordered {product}" );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
warning LA0161: LA0161_Error.cs(19,21): No IDebuggerAspectEnhancer is available for "Errors.LA0161_Error.LogWriter". RequiresDebuggerEnhancementAttribute will be ignored.
Resolution
Remove RequiresDebuggerEnhancementAttribute from your code. The attribute does nothing on your own types, and you do not need it: PostSharp already enhances the debugging of the aspects that you write.
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.LA0161_Fixed;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
LogWriter.Write( $"Entering {args.Method.Name}" );
}
}
// The class no longer has the internal attribute of PostSharp.
public static class LogWriter
{
public static void Write( string text ) => Console.WriteLine( text );
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Ordered {product}" );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
Entering PlaceOrder
Ordered Coffee
See Also
Reference