Version Used: VS2017 (15.1 (26403.3)).
Steps to Reproduce:
C#
private static string Testing() => "";
public static string TestError { get => Testing(); }
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)
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.
Looks like it's happening in 15.3.4
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.