Error MSB6006 "csc.exe" exited with code -2146232797
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**:
8.0.204
**Steps to Reproduce**:
1. Download the repro: https://github.com/SimonCropp/RuntimeHelpersRepro
2. Try to build
**Expected Behavior**:
Builds successfully
**Actual Behavior**:
Build fails
> Error MSB6006 "csc.exe" exited with code -2146232797. ClassLibrary1 C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets 84
There is an exception when building with the `dotnet build` command
```
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeAnalysis.CodeGen.ReferenceDependencyWalker.VisitSignature(ISignature signature, EmitContext context)
at Microsoft.CodeAnalysis.Emit.CommonPEModuleBuilder.GetFakeSymbolTokenForIL(ISignature symbol, SyntaxNode syntaxNode, DiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CodeGen.ILBuilder.EmitArrayBlockInitializer(ImmutableArray`1 data, SyntaxNode syntaxNode, DiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.g__tryEmitAsCachedArrayFromBlob|88_1(NamedTypeSymbol spanType, BoundExpression wrappedExpression, Int32 elementCount, ImmutableArray`1 data, ArrayTypeSymbol& arrayType, TypeSymbol elementType)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.TryEmitOptimizedReadonlySpanCreation(NamedTypeSymbol spanType, BoundExpression wrappedExpression, Boolean used, BoundExpression inPlaceTarget, Boolean& avoidInPlace, BoundExpression start, BoundExpression length)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.TryEmitOptimizedReadonlySpan(BoundObjectCreationExpression expression, Boolean used, BoundExpression inPlaceTarget, Boolean& avoidInPlace)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitObjectCreationExpression(BoundObjectCreationExpression expression, Boolean used)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpression(BoundExpression expression, Boolean used)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitArguments(ImmutableArray`1 arguments, ImmutableArray`1 parameters, ImmutableArray`1 argRefKindsOpt)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStaticCallExpression(BoundCall call, UseKind useKind)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpression(BoundExpression expression, Boolean used)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitSequenceExpression(BoundSequence sequence, Boolean used)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpressionCoreWithStackGuard(BoundExpression expression, Boolean used)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpression(BoundExpression expression, Boolean used)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatementAndCountInstructions(BoundStatement statement)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitSequencePointStatement(BoundSequencePoint node)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatements(ImmutableArray`1 statements)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitUninstrumentedBlock(BoundBlock block)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatements(ImmutableArray`1 statements)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitUninstrumentedBlock(BoundBlock block)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatementList(BoundStatementList list)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 orderedLambdaRuntimeRudeEdits, ImmutableArray`1 closureDebugInfo, ImmutableArray`1 stateMachineStateDebugInfos, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, BindingDiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, ImmutableArray`1 codeCoverageSpans, AsyncForwardEntryPoint entryPointOpt)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.b__0()
```
Note that the content of the `RuntimeHelpers` doesn't matter. The build fails also when the class is empty. When the class is renamed to anything else but `RuntimeHelpers` the build succeeds.
For the context, the error was encountered when I tried to add support for the array range operator to the [Polyfill](https://github.com/SimonCropp/Polyfill/pull/179) library that brings newer compiler features to older TFMs.
Contributor guide
Assessment
This issue has not been assessed yet.