Avoid direct descriptor comparison, so the fix can be shown #7296
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #4539
It turned out that despite
DiagnosticDescriptor
class is fully equatable, it isn't safe to compare instances in a codefix due to localized strings. For whatever reason all localizable strings indiagnostic.Descriptor
are fixed strings while singleton descriptor instances in tha analyzer contain localizable resource strings, so the comparison could never succeed and thus fixes were not shown. I guess, this might be due to serialization-deserialization between devenv and roslyn OOP. To avoid that I made it so that diagnostics are now identified viaRule
property, which is correctly passed between analyzer and a codefix provider. I've made a local setup where I verified, that this actually resolves the problem and the fix is finally shown. I don't really like the proposed fix, but that is a story for another PR)