Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentException from Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem.Create #11193

Closed
jmarolf opened this issue May 9, 2016 · 25 comments
Labels
Area-IDE Bug Contributor Pain The issue impedes progress for project collaborators. Urgency-Soon

Comments

@jmarolf
Copy link
Contributor

jmarolf commented May 9, 2016

Version Used: 1.3.0.60508

Steps to Reproduce:

  1. Git clone roslyn-analyzers git repo and checkout the sources from 8th May
  2. cibuild - to build the repo
  3. Open src\Analyzers.sln
  4. Open file: \src\Microsoft.QualityGuidelines.Analyzers\Core\UseLiteralsWhereAppropriate.cs
  5. Go to line 73 and delete all text after 'fieldInitializerValue.Type' on that line in the if condition, including the && operator.
  6. Enter '.SpecialType ==' after 'fieldInitializerValue.Type' and hit space - you should hit this crash

Expected Behavior:

No Crash

Actual Behavior:

VS Crashes with ArgumentException

   SyntaxTree '...' not found to remove

   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
   at Microsoft.CodeAnalysis.Compilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
   at Microsoft.CodeAnalysis.SymbolId.GetInteriorSymbols(ISymbol containingSymbol, List`1 symbols)
   at Microsoft.CodeAnalysis.SymbolId.GetInteriorSymbolOccurrence(ISymbol symbol)
   at Microsoft.CodeAnalysis.SymbolId.Generator.EncodeOccurrence(ISymbol symbol)
   at Microsoft.CodeAnalysis.SymbolId.Generator.VisitLocal(ILocalSymbol symbol)
   at Microsoft.CodeAnalysis.SymbolId.Generator.Visit(ISymbol symbol)
   at Microsoft.CodeAnalysis.SymbolId.CreateId(ISymbol symbol)
   at Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem.EncodeSymbol(ISymbol symbol)
   at Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem.EncodeSymbols(IReadOnlyList`1 symbols)
   at Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem.Create(String displayText, TextSpan span, IReadOnlyList`1 symbols, Int32 contextPosition, Int32 descriptionPosition, String sortText, String insertionText, Nullable`1 glyph, String filterText, Boolean preselect, SupportedPlatformData supportedPlatforms, Boolean isArgumentName, ImmutableDictionary`2 properties, ImmutableArray`1 tags, CompletionItemRules rules)
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.CreateItem(String displayText, String insertionText, Int32 position, List`1 symbols, AbstractSyntaxContext context, TextSpan span, Boolean preselect, SupportedPlatformData supportedPlatformData)
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.CreateItem(String displayText, String insertionText, Int32 position, List`1 symbols, AbstractSyntaxContext context, TextSpan span, Dictionary`2 invalidProjectMap, List`1 totalProjects, Boolean preselect)
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.<>c__DisplayClass6_0.<CreateItems>b__3(IGrouping`2 g)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.CreateItems(Int32 position, IEnumerable`1 symbols, TextSpan span, AbstractSyntaxContext context, Dictionary`2 invalidProjectMap, List`1 totalProjects, Boolean preselect)
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.<GetItemsWorkerAsync>d__15.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 System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.<ProvideCompletionsAsync>d__14.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 System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.CodeAnalysis.Completion.CompletionServiceWithProviders.<GetProviderCompletionsAsync>d__24.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 System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.CodeAnalysis.Completion.CompletionServiceWithProviders.<GetCompletionsAsync>d__18.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 System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.CodeAnalysis.SpellCheck.AbstractSpellCheckCodeFixProvider`1.<CreateSpellCheckCodeIssueAsync>d__4.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 System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.CodeAnalysis.SpellCheck.AbstractSpellCheckCodeFixProvider`1.<RegisterCodeFixesAsync>d__3.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 System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.<PerformActionAsync>d__2.MoveNext()
@gafter gafter changed the title CSharp Compiler unable to get syntax tree CSharp Compiler crash: unable to get syntax tree May 9, 2016
@mavasani
Copy link
Contributor

I am hitting this multiple times during day - this is blocking dogfooding of new Roslyn bits (D14 Update3 features) and severely impacting my productivity. Marking this as urgency soon.

@mavasani mavasani added Urgency-Soon Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner. Contributor Pain The issue impedes progress for project collaborators. labels May 10, 2016
@mavasani
Copy link
Contributor

@jaredpar @gafter - any update on this bug? I am hitting this crash at least 5-6 times daily while dogfooding latest Roslyn bits on Roslyn.sln.

@mavasani
Copy link
Contributor

Actually, isn't this as an IDE bug as the exception is coming from Intellisense completion provider (Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem.Create)?

at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
at Microsoft.CodeAnalysis.SymbolId.GetInteriorSymbols(ISymbol containingSymbol, List1 symbols) at Microsoft.CodeAnalysis.SymbolId.GetInteriorSymbolOccurrence(ISymbol symbol) at Microsoft.CodeAnalysis.SymbolId.Generator.VisitLocal(ILocalSymbol symbol) at Microsoft.CodeAnalysis.SymbolId.Generator.Visit(ISymbol symbol) at Microsoft.CodeAnalysis.SymbolId.CreateId(ISymbol symbol) at Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem.EncodeSymbols(IReadOnlyList1 symbols)
at Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem.Create(String displayText, TextSpan span, IReadOnlyList1 symbols, Int32 contextPosition, Int32 descriptionPosition, String sortText, String insertionText, Nullable1 glyph, String filterText, Boolean preselect, SupportedPlatformData supportedPlatforms, Boolean isArgumentName, ImmutableDictionary2 properties, ImmutableArray1 tags, CompletionItemRules rules)
at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.CreateItem(String displayText, String insertionText, Int32 position, List1 symbols, AbstractSyntaxContext context, TextSpan span, Boolean preselect, SupportedPlatformData supportedPlatformData) at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.CreateItem(String displayText, String insertionText, Int32 position, List1 symbols, AbstractSyntaxContext context, TextSpan span, Dictionary2 invalidProjectMap, List1 totalProjects, Boolean preselect)
at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.<>c__DisplayClass6_0.b__3(IGrouping2 g) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.CreateItems(Int32 position, IEnumerable1 symbols, TextSpan span, AbstractSyntaxContext context, Dictionary2 invalidProjectMap, List1 totalProjects, Boolean preselect)
at Microsoft.CodeAnalysis.Completion.Providers.AbstractSymbolCompletionProvider.d__15.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.Completion.Providers.AbstractSymbolCompletionProvider.d__14.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.Completion.CompletionServiceWithProviders.d__24.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 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.CodeAnalysis.Completion.CompletionServiceWithProviders.d__18.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.Editor.Implementation.IntelliSense.Completion.Controller.Session.ModelComputer.d__14.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.Editor.Implementation.IntelliSense.Completion.Controller.Session.ModelComputer.d__13.MoveNext()

@jmarolf
Copy link
Contributor Author

jmarolf commented May 10, 2016

@mavasani You're right, the ide team should look at this first.

@mavasani mavasani changed the title CSharp Compiler crash: unable to get syntax tree ArgumentException from Microsoft.CodeAnalysis.Completion.Providers.SymbolCompletionItem.Create May 10, 2016
@jaredpar
Copy link
Member

@mavasani sorry the notifications for this dropped into a Github filter and I didn't see it. Happy to move it along if turns out to be Compiler related.

@jmarolf
Copy link
Contributor Author

jmarolf commented May 12, 2016

We are seeing the syntax nodes returned from declaringLocation.GetSyntax() be from trees that are not in the compilation we get from ISourceAssemblySymbol. Shouldn't the below code always assert true?

static void TestSymbolSyntaxTrees(ISymbol containingSymbol)
{
    var compilation = (containingSymbol.ContainingAssembly as ISourceAssemblySymbol)?.Compilation;
    if (compilation != null)
    {
        foreach (var declaringLocation in containingSymbol.DeclaringSyntaxReferences)
        {
            var node = declaringLocation.GetSyntax();
            Assert.True(compilation.SyntaxTrees.Contains(node.SyntaxTree));
        }
    }
}

@jmarolf
Copy link
Contributor Author

jmarolf commented May 12, 2016

@jaredpar This looks like a compiler bug to me. I would expect (ISymbol.ContainingAssembly as ISourceAssemblySymbol)?.Compilation to return a compilation that contains the syntax trees given by ISymbol.DeclaringSyntaxReferences

@jmarolf jmarolf removed their assignment May 12, 2016
@mavasani
Copy link
Contributor

@jmarolf Your above statement is not true for merged namespace symbols. For e.g., if the symbol above is Compilation.GlobalNamepsace, then it will have declaring references from source assembly as well as referenced assemblies, as stated in the doc comments here.

@mavasani
Copy link
Contributor

@jmarolf If you still feel this is a compiler issue, can you move it to area-compilers so @jaredpar can take a look?

@jmarolf jmarolf added this to the 1.3 milestone May 15, 2016
@mavasani
Copy link
Contributor

FYI: I am still hitting this crash multiple times a day.

@jmarolf
Copy link
Contributor Author

jmarolf commented May 16, 2016

Had a meeting of the minds with @rchande and @mattwar, here is the plan:

  1. Create a test case that causes this crash.
  2. Change GetInteriorSymbols method in SymbolId from this:
private static void GetInteriorSymbols(ISymbol containingSymbol, List<ISymbol> symbols)
{
    var compilation = (containingSymbol.ContainingAssembly as ISourceAssemblySymbol)?.Compilation;
    if (compilation != null)
    {
        foreach (var declaringLocation in containingSymbol.DeclaringSyntaxReferences)
        {
            var node = declaringLocation.GetSyntax();
            if (node.Language == LanguageNames.VisualBasic)
            {
                node = node.Parent;
            }

            var semanticModel = compilation.GetSemanticModel(node.SyntaxTree);
            GetDeclaredSymbols(semanticModel, node, symbols);
        }
    }
}

To something like this (bail out if the syntax tree is not part of the semantic model):

private static void GetInteriorSymbols(ISymbol containingSymbol, List<ISymbol> symbols)
{
    var compilation = (containingSymbol.ContainingAssembly as ISourceAssemblySymbol)?.Compilation;
    if (containingSymbol.DeclaringSyntaxReferences.Any(x => !compilation.SyntaxTrees.Contains(x.SyntaxTree)))
    {
        return;
    }

    if (compilation != null)
    {
        foreach (var declaringLocation in containingSymbol.DeclaringSyntaxReferences)
        {
            var node = declaringLocation.GetSyntax();
            if (node.Language == LanguageNames.VisualBasic)
            {
                node = node.Parent;
            }

            var semanticModel = compilation.GetSemanticModel(node.SyntaxTree);
            GetDeclaredSymbols(semanticModel, node, symbols);
        }
    }
}

3.Create a bug asking for GetInteriorSymbols API on top of symbols so this can be implemented correctly.

@schuettecarsten
Copy link

I run into this bug several times a day and have several files where crash is reproduceable. Very annoying. Any idea when it gets fixed?

@rchande
Copy link
Contributor

rchande commented May 18, 2016

Soon @schuettecarsten. You can see the PR here #11398

@rchande rchande assigned jmarolf and unassigned rchande May 19, 2016
@rchande
Copy link
Contributor

rchande commented May 19, 2016

Verify plz @jmarolf

@vbfox
Copy link
Contributor

vbfox commented May 25, 2016

I hit it multiple time a day in some files, can't really change anything in some of them anymore using Visual Sudio.

Is there a timeline for a fix ?

@rchande
Copy link
Contributor

rchande commented May 25, 2016

@vbfox This is now fixed in builds of Roslyn master. @jmarolf should be able to help you install a new build.

@jmarolf
Copy link
Contributor Author

jmarolf commented May 25, 2016

@vbfox did you install an extension to get newer versions of roslyn? This crash should only be happening on builds that have the #8170 PR merged in

@CyrusNajmabadi
Copy link
Member

I've hit this on:

image

Application: devenv.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: System.AggregateException: One or more errors occurred. ---> System.ArgumentException: SyntaxTree ''
' not found to remove
Parameter name: syntaxTree
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
at Microsoft.CodeAnalysis.SymbolKey.NonDeclarationSymbolKey1.<EnumerateSymbols>d__5.MoveNext() at Microsoft.CodeAnalysis.SymbolKey.NonDeclarationSymbolKey1..ctor(TSymbol symbol, Visitor visitor)
at Microsoft.CodeAnalysis.SymbolKey.Visitor.VisitLocal(ILocalSymbol localSymbol)
at Microsoft.CodeAnalysis.CSharp.Symbols.LocalSymbol.Accept[TResult](SymbolVisitor`1 visitor)
at Microsoft.CodeAnalysis.SymbolKey.GetOrCreate(ISymbol symbol, Visitor visitor)
at Microsoft.CodeAnalysis.SymbolKey.Create(ISymbol symbol, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---

@CyrusNajmabadi
Copy link
Member

Note: this is in SymbolKey. Whereas the original fix was in SymbolId. We'll likely need the same fix in SymbolKey. Note: ideally we would not have SymbolKey at all. #11403 tracks the work to remove it and absorb it's functionality into SymbolId.

@vbfox
Copy link
Contributor

vbfox commented May 26, 2016

@jmarolf I installed a build to test the OutOfMemory problem we are having (The one that was linked in #10365) at some point but since removed it (It was creating errors at startup) maybe some bits remains.

I didn't pay attention to all the answers to #10365 about the vsix it not being removed correctly as I didn't think I was affected but it seem to be the case 😦

@mavasani
Copy link
Contributor

@CyrusNajmabadi @jmarolf - is this issue fixed now?

@mattwar
Copy link
Contributor

mattwar commented Jun 10, 2016

The exception is gone, but the correct behavior is not fixed.

@Pilchie Pilchie modified the milestones: 2.0 (Preview 4), 1.3 Jun 13, 2016
@Pilchie
Copy link
Member

Pilchie commented Jun 13, 2016

Moving to 2.0 for the correct behavior fix.

@Pilchie Pilchie modified the milestones: 2.0 (RC), 2.0 (Preview 4) Jul 31, 2016
@Pilchie Pilchie removed the Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner. label Jul 31, 2016
@Pilchie
Copy link
Member

Pilchie commented Jul 31, 2016

Removing Tenet-Reliability label, since the crash is fixed now.

@Pilchie
Copy link
Member

Pilchie commented Jul 31, 2016

Actually, closing this in favor of #11436.

@Pilchie Pilchie closed this as completed Jul 31, 2016
@jmarolf jmarolf removed their assignment Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Contributor Pain The issue impedes progress for project collaborators. Urgency-Soon
Projects
None yet
Development

No branches or pull requests

10 participants