Skip to content

System.InvalidOperationException at Microsoft.CodeAnalysis.CSharp.CodeFixes.AddImport.CSharpAddImportCodeFixProvider.GetDescription #1247

Description

@mavasani

Got the below exception while trying to apply a quick fix to add using. I don't have a concrete repro or a dump as the exception was logged in the activity log.

System.InvalidOperationException: This program location is thought to be unreachable. at Microsoft.CodeAnalysis.CSharp.CodeFixes.AddImport.CSharpAddImportCodeFixProvider.GetDescription(INamespaceOrTypeSymbol namespaceSymbol, SemanticModel semanticModel, SyntaxNode contextNode) at Microsoft.CodeAnalysis.CodeFixes.AddImport.AbstractAddImportCodeFixProvider.<RegisterCodeFixesAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.CodeFixes.CodeFixService.<>c__DisplayClass12_1.<<AppendFixesAsync>b__3>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.<PerformFunctionAsync>d__3`1.MoveNext()

Activity

  1. added this to the 1.0-rc2 milestone on Mar 13, 2015
  2. mavasani commented on Mar 13, 2015

    @mavasani
    ContributorAuthor

    I just noticed that the file where I was applying the quick fix had static usings and after the fix was applied, the new using was added after the static usings, causing a squiggle for newly added using in the file:

    using System;
    using System.Globalization;
    using System.IO;
    using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
    using Microsoft.CodeAnalysis.Test.Utilities;
    using Xunit;

    using static Microsoft.CodeAnalysis.Test.Utilities.SharedResourceHelpers;
    using static Microsoft.CodeAnalysis.DiagnosticExtensions;
    using Microsoft.CodeAnalysis.CommonDiagnosticAnalyzers; // this is the added using with error

  3. srivatsn commented on Mar 13, 2015

    @srivatsn
    Contributor

    Looking at the GetDescription method, it looks like we don't know why we would reach this place. @jmarolf, do you have any ideas when this could get hit. Otherwise, I'm not sure if this is actionalble without a repro or a dump.

  4. srivatsn commented on Mar 13, 2015

    @srivatsn
    Contributor

    Ah looks like our comments crossed midstream. using static is likely the missing case.

  5. mavasani commented on Mar 13, 2015

    @mavasani
    ContributorAuthor

    Yes, and the type I did an add using for was a nested static type, i.e. CommonDiagnosticAnalyzers is actuall a static class, so the above added using should be "using static Microsoft.CodeAnalysis.CommonDiagnosticAnalyzers".

    I wasn't able to repro the exception again though, even after restarting VS. The squiggle in the added using always shows up CTRL + DOT + ENTER

  6. jmarolf commented on Mar 13, 2015

    @jmarolf
    Contributor

    At the very least we should handle this case. I suspect that the logic which determines if a using already exists does not take static into account.

  7. jmarolf commented on Mar 17, 2015

    @jmarolf
    Contributor

    Fixed with pull request #1302

  8. assigned and unassigned on Mar 17, 2015
  9. added a commit that references this issue on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions