Roslyn: Warning Level 3 breaks Remove Unused Usings and Simplify Type Name

Created on 22 Jun 2017  路  6Comments  路  Source: dotnet/roslyn

Version Used: 15.3 Preview 2.1

Steps to Reproduce:

  1. Set C# warning level to 3
  2. Add the following code

    using System;
    using System.Threading;
    
    class Class
    {
      System.Action _action = (Action)(() => { });
    }
    

Expected Behavior:

  1. System.Threading is indicated as an unused using directive, and the light bulb allows its removal
  2. The System. qualification in System.Action is marked as unnecessary, and the light bulb allows the type to be simplified to Action

Actual Behavior:

  1. Both using directives are indicated as used
  2. System.Action is not indicated as overly qualified

Neither the light bulb nor the Remove and Sort Usings command may be used to make the desired corrections.

Area-Compilers Bug Resolution-Fixed

Most helpful comment

If this was resolved in January, why am I still seeing this issue in June?

All 6 comments

I suspect the "info" diagnostic for this gets filtered away in this case.

This is caused by the following:

https://github.com/dotnet/roslyn/blob/5b636eb916ad317a09341e59e27ba1fcdd7b71cd/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs#L496-L497

It seems the fix is removing the dependence of warning level on severity. If a user configures a rule with a specific severity, the current warning level shouldn't undo that.

Assigned to Sam since he already has a PR for this.

If this was resolved in January, why am I still seeing this issue in June?

This happens to me with Visual studio 2019. The cause is the theme Blue High Constrast. Using other themes fix the issue.

Reference
https://www.devexpress.com/Support/Center/Question/Details/T588868/visual-studio-2017-unused-using-is-not-grayed-out

change the theme to Blue not (blue high contrast), High Contrast will not grey out the unused namespace.

Was this page helpful?
0 / 5 - 0 ratings