Version Used:
I copied the global.json from the samples.
I'm using Visual Studio Community 2019 - Version 16.6.0 Preview 6.0 (just installed).
Steps to Reproduce:
Unzip the attached file: generator.zip
From a developer prompt for that same preview, run msbuild -r from the Tests folder.
.editorconfig to .editorconfig.none and build again, it succeeds this time.The approach to referencing the generator is the same shown in the samples:
<ItemGroup>
<ProjectReference Include="..\GraphQL.Generator\GraphQL.Generator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>
NOTE: tried with int.preview, the same package versions in the annoucement blog post,
with and without the global.json, before and after installing the .NET 5 preview 3,
command line and IDE build, and referencing the analyzer directly from its output dir.
Also, it didn't seem to matter what content the .editorconfig even had: it's mostly empty
(just root=true in the attachment) and even leaving it entirely empty fails the build too.
Expected Behavior:
Build works fine with or without a .editorconfig
Actual Behavior:
Exception during build:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : Unhandled Exception: System.IndexOutOfRangeException: In
dex was outside the bounds of the array. [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CommonCompiler.CreateAnalyz
erConfigOptionsProvider(IEnumerable`1 syntaxTrees, ImmutableArray`1 sourceFileAnalyzerConfigOptions, ImmutableArray`1 additionalFiles, ImmutableArray`1 additionalFileOptions) [C:\Delete\ge
nerator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CommonCompiler.CompileAndEm
it(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 additionalTextFiles, AnalyzerConfigSet analyzerConfigSet, ImmutableArray`1 s
ourceFileAnalyzerConfigOptions, ImmutableArray`1 embeddedTexts, DiagnosticBag diagnostics, CancellationToken cancellationToken, CancellationTokenSource& analyzerCts, Boolean& reportAnalyze
r, AnalyzerDriver& analyzerDriver) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CommonCompiler.RunCore(Text
Writer consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CommonCompiler.Run(TextWrit
er consoleOutput, CancellationToken cancellationToken) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.<>c_
_DisplayClass1_0.<Run>b__0(TextWriter tw) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CommandLine.ConsoleUtil.Run
WithUtf8Output[T](Func`2 func) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(
String[] args, BuildPaths buildPaths, TextWriter textWriter, IAnalyzerAssemblyLoader analyzerLoader) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CommandLine.BuildClient.Run
LocalCompilation(String[] arguments, BuildPaths buildPaths, TextWriter textWriter) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CommandLine.BuildClient.Run
Compilation(IEnumerable`1 originalArguments, BuildPaths buildPaths, TextWriter textWriter, String pipeName) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CommandLine.BuildClient.Run
(IEnumerable`1 arguments, RequestLanguage language, CompileFunc compileFunc) [C:\Delete\generator\Tests\Tests.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.
Main(String[] args) [C:\Delete\generator\Tests\Tests.csproj]
Tagging @chsienki
Ah, I think I see what's happening. We're trying to retrieve the AnalyzerOptions for a generated syntax tree, and there aren't any to return because they didn't exist when we parsed the editorconfig
There is an open question as to whether analyzer options should actually apply to generated SyntaxTrees they don't actually have a path per se, and they aren't really under the users control.
I think we'll probably go the route of ignoring options on generated syntax trees, but we'll need to think through the scenarios to make sure it makes sense to do so.
i've got the same error here after adding .editorconfig file :
Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Microsoft.CodeAnalysis.CommonCompiler.CreateAnalyzerConfigOptionsProvider(IEnumerable`1 syntaxTrees, ImmutableArray`1 sourceFileAnalyzerConfigOptions, ImmutableArray`1 additionalFiles, ImmutableArray`1 additionalFileOptions)
at Microsoft.CodeAnalysis.CommonCompiler.CompileAndEmit(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 additionalTextFiles, AnalyzerConfigSet analyzerConfigSet, ImmutableArray`1 sourceFileAnalyzerConfigOptions, ImmutableArray`1 embeddedTexts, DiagnosticBag diagnostics, CancellationToken cancellationToken, CancellationTokenSource& analyzerCts, Boolean& reportAnalyzer, AnalyzerDriver& analyzerDriver)
at Microsoft.CodeAnalysis.CommonCompiler.RunCore(TextWriter consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CommonCompiler.Run(TextWriter consoleOutput, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.<>c__DisplayClass1_0.<Run>b__0(TextWriter tw)
at Microsoft.CodeAnalysis.CommandLine.ConsoleUtil.RunWithUtf8Output[T](Boolean utf8Output, TextWriter textWriter, Func`2 func)
at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(String[] args, BuildPaths buildPaths, TextWriter textWriter, IAnalyzerAssemblyLoader analyzerLoader)
at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunLocalCompilation(String[] arguments, BuildPaths buildPaths, TextWriter textWriter)
at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation(IEnumerable`1 originalArguments, BuildPaths buildPaths, TextWriter textWriter, String pipeName)
at Microsoft.CodeAnalysis.CommandLine.BuildClient.Run(IEnumerable`1 arguments, RequestLanguage language, CompileFunc compileFunc)
at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore(String[] args)
at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args)
and after hooking to the CreateAnalyzerConfigOptionsProvider call, i see that i have 194 syntax trees and only 193 sourceFileAnalyzerConfigOptions items.. so it's normal to have an IndexOutOfRangeException

/cc @chsienki, i hope you can resolve this bug before imminent VS 16.6 release :)
Yep, thanks for the repro, a fix is currently in the works.
We've pushed a temporary fix for this (see #44221), meaning you should no longer see crashes when combining editorconfigs and generators.
The generated syntax trees don't yet respect the options in the editorconfig; that work is planned and can be tracked via #44223
@chsienki is there a workaround for this when using the 3.1.3xx non-preview SDKs? or is there any chance to backport this to this release train?
Update: after digging around a little, setting DiscoverEditorConfigFiles to false works around the issue.
Most helpful comment
We've pushed a temporary fix for this (see #44221), meaning you should no longer see crashes when combining editorconfigs and generators.
The generated syntax trees don't yet respect the options in the editorconfig; that work is planned and can be tracked via #44223