JetBrains / JetBrains.Annotations

Annotations to increase the accuracy of JetBrains ReSharper/Rider code inspections
https://www.jetbrains.com/help/resharper/Code_Analysis__Code_Annotations.html
MIT License
31 stars 18 forks source link

Cannot use UsedImplicitly attribute with the "WithInheritors" flag due to assembly versioning bug. #4

Closed Mike-Logit closed 2 years ago

Mike-Logit commented 2 years ago

Hi, I hope this is the right place to report a bug. I cannot use [UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)] in my codebase because there is a dependency issue with JetBrains.Annotations. It says:

The type 'ImplicitUseTargetFlags' exists in both 'JetBrains.Annotations, Version=2021.2.0.0, ...' and 'Lambda2Js.Signed, Version=3.1.3.0, ...',

but JetBrains.Annotations has a dependency on .NetStandard v1.0, and .NetStandard v1.0 has a dependency on that Lambda2Js.Signed package, so I cannot fix the dependency problem myself.

I want to use these flags (e.g., ImplicitUseTargetFlags) but can only use the UsedImplicitly attribute without flags. I hope this can get fixed as inheritance would be a great feature to use with these attributes. This would let me have a base class with the UsedImplicitly attribute and then all my derived classes would not need to also have this attribute and it can be assumed that if I'm deriving from the base class then it will be used implicitly (which is great for many design patterns). Thank you.

controlflow commented 2 years ago

Hi. Unfortunately, this full name clash issue is caused by the Lambda2Js.Signed library having not all types from JetBrains.Annotations namespace hidden under internal accessibility modifiers: https://github.com/gearz-lab/lambda2js/blob/c6cab82ac3c35d6e3ee85a7c50b2dc3a07892d26/Lambda2Js/JetBrains.Annotations.cs#L342

You probably can send a PR to this library author to fix this visibility issue. As a workaround on your side you can use C# extern alias functionality to solve the naming clash: image

Unfortunately, there is nothing else we can do on our side to solve this.

Mike-Logit commented 2 years ago

@controlflow the Lambda2js.Signed dependency problem has been fixed and released to NuGet: https://github.com/gearz-lab/lambda2js/issues/33

I had to install Lambda2js.Signed explicitly to override the behavior from the Lambda2js.Signed v3.1.3 version that JetBrains.Annotations v2022.1.0 currently uses as a dependency.

Now I can use the attribute with the flags as expected but it might be worth updating JetBrains.Annotations with the latest version (3.1.4 I think) of Lambda2js.Signed to avoid needing to explicitly install the Lambda2js.Signed package.