Roslyn: ExtractMethodCodeRefactoringProvider crash on method highlight in expression body

Created on 11 Apr 2017  路  10Comments  路  Source: dotnet/roslyn

Version Used: VS2017 (15.1 (26403.3)).

Steps to Reproduce:

  1. Create empty ASP.NET Web Application project (I have only testet with this project type).
  2. Create empty class in any namespace.
  3. Insert the following code:
    C# private static string Testing() => ""; public static string TestError { get => Testing(); }
    Highlight Testing in the TestError property.

If refactored to ... TestError => Testing() ?? ""; Everything is fine.
The error also happens with a setter.

Expected Behavior: No thrown exceptions.

Actual Behavior: Thrown exceptions and ExtractMethodCodeRefactoringProvider crashes.


Stack trace from the error:

System.InvalidOperationException : Unexpected false
  at Roslyn.Utilities.Contract.ThrowIfFalse(Boolean condition, String message)
  at Microsoft.CodeAnalysis.CSharp.ExtractMethod.CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.GetCallSiteContainerFromExpression()
  at Microsoft.CodeAnalysis.CSharp.ExtractMethod.CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.GetOutermostCallSiteContainerToProcess(CancellationToken cancellationToken)
  at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.CodeGenerator`3.GenerateAsync[TStatement, TExpression, TNodeUnderContainer] (<Unknown Parameters>)
  at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.ExtractMethodAsync(<Unknown Parameters>)
  at async Microsoft.CodeAnalysis.ExtractMethod.AbstractExtractMethodService`3.ExtractMethodAsync[TValidator, TExtractor, TResult] (<Unknown Parameters>)
  at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.GetCodeActionAsync(<Unknown Parameters>)
  at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
  at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)
  at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
Area-IDE Bug Resolution-Duplicate

All 10 comments

Note - I can repro in 15.1, but not the latest 15.3 bits, but I didn't see a dupe with a quick search. Can you check for a dupe and a unit test for this case?

This also happens when highlighting other things. Actually just any text between two spaces after the => and before the semi-colon. This could be the null-coalescing operator or the 0 in get => Testing2() ?? 0; - except the parentheses and never if there is a syntax error.

I could not find a dupe and no unit test. I do not feel confident to write one.

I'm getting this inside a C# DLL source file. All I do is put the caret on a field inside a property and boom. I wasn't refactoring anything, but I figure maybe it was going to tell about options for refactoring. The class in question is nested inside another class in a namespace.

System.InvalidOperationException : Unexpected false
   at Roslyn.Utilities.Contract.ThrowIfFalse(Boolean condition,String message)
   at Microsoft.CodeAnalysis.CSharp.ExtractMethod.CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.GetCallSiteContainerFromExpression()
   at Microsoft.CodeAnalysis.CSharp.ExtractMethod.CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.GetOutermostCallSiteContainerToProcess(CancellationToken cancellationToken)
   at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.CodeGenerator`3.GenerateAsync[TStatement,TExpression,TNodeUnderContainer](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.ExtractMethodAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.ExtractMethod.AbstractExtractMethodService`3.ExtractMethodAsync[TValidator,TExtractor,TResult](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.GetCodeActionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Yes, the issue is still Open, and is currently targeted at the 15.3 milestone.

This was fixed in #18375.

Its happening for me on the latest version

The issues happening today are not the same as the issue that led to this report, so I'm going to close this one as a duplicate of the very old one.

Was this page helpful?
0 / 5 - 0 ratings