Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error MSB6006 "csc.exe" exited with code -2146232797 #73252

Open
gao-artur opened this issue Apr 27, 2024 · 5 comments
Open

Error MSB6006 "csc.exe" exited with code -2146232797 #73252

gao-artur opened this issue Apr 27, 2024 · 5 comments
Assignees
Milestone

Comments

@gao-artur
Copy link

gao-artur commented Apr 27, 2024

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.<TryEmitOptimizedReadonlySpanCreation>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.<CompileNamedTypeAsync>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 library that brings newer compiler features to older TFMs.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 27, 2024
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 27, 2024
@jaredpar jaredpar added this to the 17.11 milestone Apr 27, 2024
@cston
Copy link
Member

cston commented Apr 27, 2024

It looks like the compiler is not checking for the existence of System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray.

@gao-artur
Copy link
Author

@cston does it mean I can just add this as a workaround?

[Intrinsic]
public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field, Inherited = false)]
internal sealed class IntrinsicAttribute : Attribute
{
}

It seems to work, but I just want to confirm this is the correct way to do that.

@cston
Copy link
Member

cston commented Apr 27, 2024

@gao-artur, I'm not sure if re-declaring the existing BCL method as extern is expected to work.

However, in general, it does appear that re-declaring an existing BCL type in source will essentially hide any well-known members of that type that the compiler may depend on that are not also re-declared.

@gao-artur
Copy link
Author

gao-artur commented Apr 27, 2024

It works, all tests pass, but ReSharper unit tests runner shows the following error. Is it safe to ignore, or can it explode in runtime?

ERROR TestRunner: JetBrains.ReSharper.TestRunner.Adapters.NUnit3.NUnitTestReporter Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
----> Could not load type 'System.Runtime.CompilerServices.RuntimeHelpers' from assembly 'Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the method 'InitializeArray' has no implementation (no RVA).

@CyrusNajmabadi
Copy link
Member

@gao-artur you'd have to try out and see.

@jaredpar jaredpar assigned cston and unassigned jjonescz Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants