aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
256 stars 123 forks source link

EditorConfig expression-bodied member enforcement throws error #991

Closed scottaddie closed 7 years ago

scottaddie commented 7 years ago

I'm using VS 2017 Enterprise RC4 (26206.0) on Windows 10 (version 1607). The type of project used here is an ASP.NET Core web application targeting .NET Core. Here are the steps to reproduce:

  1. Clone https://github.com/scottaddie/TagHelpersDemo
  2. Add a .editorconfig file to the Solution Items solution folder. It should contain the following:
    
    # top-most EditorConfig file
    root = true

[*.cs] csharp_style_expression_bodied_methods = true : error

3. Modify the `Controllers\HomeController.cs` file's `Index` action method to resemble the following:
```c#
public IActionResult Index()
{
    return View();
}
  1. After saving the changes to the Index action method, a red squiggly line appears under return View();. Hover over this, and click the "Show potential fixes" link. The following error appears:

editorconfig_error

Here's the stack trace:

System.NullReferenceException : Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.Extensions.ArrowExpressionClauseSyntaxExtensions.ConvertToBlock(ArrowExpressionClauseSyntax arrowExpression,SyntaxToken semicolonToken,Boolean createReturnStatementForExpression)
   at Microsoft.CodeAnalysis.CSharp.UseExpressionBody.AbstractUseExpressionBodyCodeFixProvider`1.WithGenerateBody(TDeclaration declaration,OptionSet options)
   at Microsoft.CodeAnalysis.CSharp.UseExpressionBody.AbstractUseExpressionBodyCodeFixProvider`1.Update(TDeclaration declaration,Boolean preferExpressionBody,OptionSet options)
   at Microsoft.CodeAnalysis.CSharp.UseExpressionBody.AbstractUseExpressionBodyCodeFixProvider`1.AddEdits(SyntaxEditor editor,Diagnostic diagnostic,OptionSet options,Boolean preferExpressionBody,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.UseExpressionBody.AbstractUseExpressionBodyCodeFixProvider`1.FixAllAsync(Document document,ImmutableArray`1 diagnostics,SyntaxEditor editor,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.<>c__DisplayClass2_0.<FixAllAsync>b__0(SyntaxEditor editor)
   at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputePreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

/cc: @morrisjoe

mlorbetske commented 7 years ago

Moving this to https://github.com/dotnet/roslyn/issues/17068