In the process of determining where the (Item)CanBeNull/(Item)NotNull attributes are defined, their visibility is taken into account. Internal attributes are chosen only when the project asking for them is the same project.
However, for better performance, the last-known location of these attributes is cached. The bug here is that when retrieving the locations from cache, visibility is not re-checked.
Repro steps:
Create class library
Add internal annotations (see below)
Add a string property, wait for analyzer to report and apply code fix
Add new Console application to the same solution (do not restart VS)
Add project reference from class library to console application
In the console application, add new class with string property.
Wait for analyzer to report on the new string property (which it should not)
Apply suggested code fix and observe broken build
Code for step 2:
internal class CanBeNullAttribute : Attribute { }
internal class NotNullAttribute : Attribute { }
internal class ItemNotNullAttribute : Attribute { }
internal class ItemCanBeNullAttribute : Attribute { }
In the process of determining where the (Item)CanBeNull/(Item)NotNull attributes are defined, their visibility is taken into account. Internal attributes are chosen only when the project asking for them is the same project. However, for better performance, the last-known location of these attributes is cached. The bug here is that when retrieving the locations from cache, visibility is not re-checked.
Repro steps:
Code for step 2: