Skip to content

[RequiresThreadSafe] cannot be used: PS0171 on its own MulticastAttributeUsage #335

Open

Description

[RequiresThreadSafe] (PostSharp.Patterns.Threading) cannot be used: any project that applies it fails to build.

Repro

public class Worker
{
    public void Share( [RequiresThreadSafe] object state ) { }
}

The build fails with:

error PS0171: Error in MulticastAttributeUsage applied on type 'PostSharp.Patterns.Threading.RequiresThreadSafeAttribute': strict attribute inheritance is not supported on properties and events.
error PS0055: The processing of multicast attributes cannot continue because of the previous errors.

Seen with 2027.0.7 (local build). The cause is in the attribute itself, so all versions are affected.

Cause

RequiresThreadSafeAttribute is declared with:

[MulticastAttributeUsage( MulticastTargets.Field | MulticastTargets.Property | MulticastTargets.Parameter, Inheritance = MulticastInheritance.Strict )]

MulticastAttributeTask rejects Inheritance = Strict on any attribute whose valid targets include Property or Event (PS0171). This check and this declaration both date from 2014. Nothing in the repository applies the attribute or tests it.

Fix

Remove Inheritance = MulticastInheritance.Strict, or remove MulticastTargets.Property from the valid targets, and add a test that applies the attribute to a field, a property and a parameter. The documentation section about the attribute was removed from postsharp/PostSharp.Documentation#58 until it works; restore it with the fix.

-- Claude for Gael

Activity

  1. gfraiteur commented on Oct 28, 2026

    @gfraiteur
    MemberAuthor

    There is a conceptual issue. I think the correct behavior is to report the error only when the attribute is applied to an invalid target, not when we validate the attribute itself. Any other fix breaks backward compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions