Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

[SiField(AttributeExclude = true)] & <WarningDisplayed>k__BackingField


I testing the postsharp addin and have the following code in program.cs

[assembly: SiTrace(SessionPolicy = SessionPolicy.TypeName, IncludeArguments = true, IncludeReturnValue = true, IncludeSpecialNames = false)] [assembly: SiException(SessionPolicy = SessionPolicy.TypeName)] [assembly: SiField(SessionPolicy = SessionPolicy.TypeName)]

I have a method that excutes every second and I don’t want to include a field as a watch so I decorate the method with:

[SiTrace(AttributeExclude = true)] [SiException(AttributeExclude = true)] void timer1_Tick(object sender, EventArgs e)

and the property with:

[SiField(AttributeExclude = true)] public static bool WarningDisplayed {get; set;}

The log entry

WarningDisplayed = False [was: False]

is properly suppressed but the following is still logged:

k__BackingField = False [was: False]

How can I get that suppressed as well.

Also, in my program setup, what’s the format for setting the Watch attribute to false instead of it’s default true as in the following decoration:

[assembly: SiField(SessionPolicy = SessionPolicy.TypeName)]


Hello Glen,

Thanks for your posting. The second field is still logged because that’s the auto-generated and internal field that backs the WarningDisplayed property. I’m not sure if it’s possible to exclude such internal/implicit fields (I would recommend asking the PostSharp support for details). You should be able to get it working by using an explicit field in the WarningDisplayed property instead of the auto getter/setter.

Regarding the default value: the SmartInspect PostSharp adapter logs the field value every time the field value changes and doesn’t work with a default value or similar. When and if this change event handler is called is determined by PostSharp and SmartInspect cannot influence this as far as I know.

I hope this helps!



Thank you for your comments - they will assist me greatly with coming to grips with Postsharp integration/usage.

Unfortunately the Postsharp people are unwilling to assist me with third party aspects so I am using your example as a base to write my own aspects.


Hello Glen,

I’m happy to help and please let us know in case any further questions come up. While the SmartInspect PostSharp adapter is already very useful, it may be a bit inflexible and I agree that writing custom aspects can make sense, depending on your requirements. You can then also use newer features of PostSharp as an additional bonus.