dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.05k stars 4.04k forks source link

One of our projects fails to build with: "csc.exe" exited with code -2146232797 #33542

Closed vsfeedback closed 5 years ago

vsfeedback commented 5 years ago

I don't have any idea why this would happen, this used to build on everything except Visual Studio 2019 Preview 2, preview 1.1 worked.

This issue has been moved from https://developercommunity.visualstudio.com/content/problem/434543/one-of-our-projects-fails-to-build-with-cscexe-exi.html VSTS ticketId: 776735 These are the original issue comments:

tstedel on 1/31/2019, 05:49 PM (19 days ago):

Still does this in preview 2.1. It hangs for a very long time and then doesn't build.

1>------ Build started: Project: POS_Connector.Core, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets(52,5): error MSB6006: "csc.exe" exited with code -2146232797.
========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========

tstedel on 1/31/2019, 06:41 PM (19 days ago):

using System.Threading.Tasks;
namespace ConsoleApp6
{
class Program
{
static async Task Main(string[] args)
{
try
{
try
{
return;
}
finally
{
await Task.CompletedTask;
}
}
catch { }
finally
{
await Task.CompletedTask;
}
}
}
}

tstedel on 1/31/2019, 06:42 PM (19 days ago):

What I just posted is the minimum necessary to reproduce this issue

These are the original issue solutions: (no solutions)

sharwell commented 5 years ago

@jaredpar I believe this is COR_E_FAILFAST

RikkiGibson commented 5 years ago

Looks like this builds in dev15 but not dev16.

RikkiGibson commented 5 years ago

I have a reproducer in a branch. Check out the stack trace.

Microsoft.CodeAnalysis.dll!Roslyn.Utilities.ExceptionUtilities.UnexpectedValue(object o) Line 18    C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.CodeGen.ILOpCodeExtensions.GetLeaveOpcode(System.Reflection.Metadata.ILOpCode opcode) Line 38 C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.CodeGen.ILBuilder.BasicBlock.RewriteBranchesAcrossExceptionHandlers() Line 294    C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.CodeGen.ILBuilder.RewriteBranchesAcrossExceptionHandlers() Line 761   C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() Line 853    C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() Line 189  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() Line 270   C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.Generate(out int asyncCatchHandlerOffset, out System.Collections.Immutable.ImmutableArray<int> asyncYieldPoints, out System.Collections.Immutable.ImmutableArray<int> asyncResumePoints) Line 202 C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder moduleBuilder, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol method, int methodOrdinal, Microsoft.CodeAnalysis.CSharp.BoundStatement block, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeGen.LambdaDebugInfo> lambdaDebugInfo, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeGen.ClosureDebugInfo> closureDebugInfo, Microsoft.CodeAnalysis.CSharp.StateMachineTypeSymbol stateMachineTypeOpt, Microsoft.CodeAnalysis.CodeGen.VariableSlotAllocator variableSlotAllocatorOpt, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Microsoft.CodeAnalysis.CodeGen.DebugDocumentProvider debugDocumentProvider, Microsoft.CodeAnalysis.CSharp.ImportChain importChainOpt, bool emittingPdb, bool emitTestCoverageData, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeGen.SourceSpan> dynamicAnalysisSpans) Line 1409  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(Microsoft.CodeAnalysis.CSharp.TypeCompilationState compilationState) Line 696  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol containingType) Line 602  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MethodCompiler.VisitNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol symbol, Microsoft.CodeAnalysis.CSharp.TypeCompilationState arg) Line 376    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol.Accept<Microsoft.CodeAnalysis.CSharp.TypeCompilationState, object>(Microsoft.CodeAnalysis.CSharp.CSharpSymbolVisitor<Microsoft.CodeAnalysis.CSharp.TypeCompilationState, object> visitor, Microsoft.CodeAnalysis.CSharp.TypeCompilationState argument) Line 576 C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamespace(Microsoft.CodeAnalysis.CSharp.Symbols.NamespaceSymbol symbol) Line 355  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MethodCompiler.VisitNamespace(Microsoft.CodeAnalysis.CSharp.Symbols.NamespaceSymbol symbol, Microsoft.CodeAnalysis.CSharp.TypeCompilationState arg) Line 330    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.NamespaceSymbol.Accept<Microsoft.CodeAnalysis.CSharp.TypeCompilationState, object>(Microsoft.CodeAnalysis.CSharp.CSharpSymbolVisitor<Microsoft.CodeAnalysis.CSharp.TypeCompilationState, object> visitor, Microsoft.CodeAnalysis.CSharp.TypeCompilationState argument) Line 135 C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamespace(Microsoft.CodeAnalysis.CSharp.Symbols.NamespaceSymbol symbol) Line 355  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethodBodies(Microsoft.CodeAnalysis.CSharp.CSharpCompilation compilation, Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder moduleBeingBuiltOpt, bool emittingPdb, bool emitTestCoverageData, bool hasDeclarationErrors, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, System.Predicate<Microsoft.CodeAnalysis.CSharp.Symbol> filterOpt, System.Threading.CancellationToken cancellationToken) Line 143  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CompileMethods(Microsoft.CodeAnalysis.Emit.CommonPEModuleBuilder moduleBuilder, bool emittingPdb, bool emitMetadataOnly, bool emitTestCoverageData, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, System.Predicate<Microsoft.CodeAnalysis.ISymbol> filterOpt, System.Threading.CancellationToken cancellationToken) Line 2626 C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Compilation.Emit(System.IO.Stream peStream, System.IO.Stream metadataPEStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ResourceDescription> manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.IMethodSymbol debugEntryPoint, System.IO.Stream sourceLinkStream, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.EmbeddedText> embeddedTexts, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData, System.Threading.CancellationToken cancellationToken) Line 2405  C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Compilation.Emit(System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ResourceDescription> manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.IMethodSymbol debugEntryPoint, System.IO.Stream sourceLinkStream, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.EmbeddedText> embeddedTexts, System.IO.Stream metadataPEStream, System.Threading.CancellationToken cancellationToken) Line 2349   C#
Roslyn.Test.Utilities.dll!Microsoft.CodeAnalysis.DiagnosticExtensions.GetEmitDiagnostics<Microsoft.CodeAnalysis.CSharp.CSharpCompilation>(Microsoft.CodeAnalysis.CSharp.CSharpCompilation c, Microsoft.CodeAnalysis.Emit.EmitOptions options, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ResourceDescription> manifestResources) Line 276    C#
Roslyn.Test.Utilities.dll!Microsoft.CodeAnalysis.DiagnosticExtensions.VerifyEmitDiagnostics<Microsoft.CodeAnalysis.CSharp.CSharpCompilation>(Microsoft.CodeAnalysis.CSharp.CSharpCompilation c, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.Test.Utilities.DiagnosticDescription[] expected) Line 265   C#
Roslyn.Test.Utilities.dll!Microsoft.CodeAnalysis.DiagnosticExtensions.VerifyEmitDiagnostics<Microsoft.CodeAnalysis.CSharp.CSharpCompilation>(Microsoft.CodeAnalysis.CSharp.CSharpCompilation c, Microsoft.CodeAnalysis.Test.Utilities.DiagnosticDescription[] expected) Line 282    C#
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.dll!Microsoft.CodeAnalysis.CSharp.UnitTests.EmitErrorTests.Repro_33542() Line 393  C#

Seems like GetLeaveOpcode is receiving a Beq and doesn't like it. IL for Roslyn 2.9 can be found here: https://sharplab.io/#v2:C4LglgNgNAJiDUAfAAgBgATIIwFYDcAsAFDEB2AhgLYCmAzgA7kDG16AwgPam0cTUCC9egDZixAN5iiyAEyYsAdimSS0rMMwAOTBoCy5MKQAU2VAG0AuunIAnAOa0AlMqnAbATxeq3n1SuLICoSqAL5SAGaG5BAQvhJSyACcOgB0nJT0fMDUMMjCwcRhoVJM5MBMABbo4uhFxJEUMXFE/tLJeWkcGVk5eQVEdQNSgyFAA===

JohnGalt1717 commented 5 years ago

I'm getting this with a dot.net core 2.2 (SDK 105) project. Just yesterday it started failing in both the latest version of VS.net 2017 and the RTM of 2019 if it matters.

building the solution from the command prompt with dotnet build works fine.

jaredpar commented 5 years ago

@JohnGalt1717 is there some source you could share out that would help us understand if this is related to other issues we're looking into?

JohnGalt1717 commented 5 years ago

@jaredpar Unfortunately not. One project doesn't work, the other does.

There appears to be something really wonky going on with .NET core 2.2. sdks though. VS.net 2019 installs 2.2.202 but the most recent listed on dot.net is 2.2.105 which makes no sense at all and I think is part of the problem.

Using 2.2.105 in our global.json file using FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build in our docker results in the following error now as well which doesn't happen at command prompt in windows:

/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error : FailFast: [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error : System.InvalidOperationException: Unexpected value 'Beq' of type 'System.Reflection.Metadata.ILOpCode' [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILOpCodeExtensions.GetLeaveOpcode(ILOpCode opcode) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BasicBlock.RewriteBranchesAcrossExceptionHandlers() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RewriteBranchesAcrossExceptionHandlers() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.Generate(Int32& asyncCatchHandlerOffset, ImmutableArray`1& asyncYieldPoints, ImmutableArray`1& asyncResumePoints) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 closureDebugInfo, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, Boolean emitTestCoverageData, ImmutableArray`1 dynamicAnalysisSpans) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass21_0.<CompileNamedTypeAsTask>b__0() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :  [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at System.Environment.FailFast(System.String, System.Exception) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at System.Environment.FailFast(System.String, System.Exception) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.FatalError.Report(System.Exception, System.Action`1<System.Exception>) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.FatalError.ReportUnlessCanceled(System.Exception) [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass21_0.<CompileNamedTypeAsTask>b__0() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILOpCodeExtensions.GetLeaveOpcode(System.Reflection.Metadata.ILOpCode) [/src/...]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder+BasicBlock.RewriteBranchesAcrossExceptionHandlers() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RewriteBranchesAcrossExceptionHandlers() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.Generate(Int32 ByRef, System.Collections.Immutable.ImmutableArray`1<Int32> ByRef, System.Collections.Immutable.ImmutableArray`1<Int32> ByRef) 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Int32, Microsoft.CodeAnalysis.CSharp.BoundStatement, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.LambdaDebugInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.ClosureDebugInfo>, Microsoft.CodeAnalysis.CSharp.StateMachineTypeSymbol, Microsoft.CodeAnalysis.CodeGen.VariableSlotAllocator, Microsoft.CodeAnalysis.DiagnosticBag, Microsoft.CodeAnalysis.CodeGen.DebugDocumentProvider, Microsoft.CodeAnalysis.CSharp.ImportChain, Boolean, Boolean, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.SourceSpan>) /usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(Microsoft.CodeAnalysis.CSharp.TypeCompilationState) [/src/...]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol) [/src/...]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass21_0.<CompileNamedTypeAsTask>b__0() [/src/XXX/XXX.csproj]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Roslyn.Utilities.UICultureUtilities+<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef) 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at System.Threading.ThreadPoolWorkQueue.Dispatch() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :  
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error : Exception details: 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error : System.InvalidOperationException: Unexpected value 'Beq' of type 'System.Reflection.Metadata.ILOpCode' [/src/...]
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILOpCodeExtensions.GetLeaveOpcode(ILOpCode opcode) 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BasicBlock.RewriteBranchesAcrossExceptionHandlers() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RewriteBranchesAcrossExceptionHandlers() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.Generate(Int32& asyncCatchHandlerOffset, ImmutableArray`1& asyncYieldPoints, ImmutableArray`1& asyncResumePoints) 
/usr/share/dotnet/sdk/2.2.202/Roslyn/Microsoft.CSharp.Core.targets(58,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 closureDebugInfo, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, Boolean emitTestCoverageData, ImmutableArray`1 dynamicAnalysisSpans) 
...
JohnGalt1717 commented 5 years ago

Only other thing I can think of is that this project references Mammoth which is a .net 4.6.1 nuget package that would warn in the past but would run/build fine.

Here's the full csproj of the failing project:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netcoreapp2.2</TargetFramework>
        <DebugType>portable</DebugType>
        <LangVersion>8.0</LangVersion>
        <NullableReferenceTypes>true</NullableReferenceTypes>
        <NullableContextOptions>enable</NullableContextOptions>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="AspNet.Security.OpenIdConnect.Extensions" Version="2.0.0" />
        <PackageReference Include="AspNet.Security.OpenIdConnect.Primitives" Version="2.0.0" />
        <PackageReference Include="AspNet.Security.OpenIdConnect.Server" Version="2.0.0" />
        <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
        <PackageReference Include="DocumentFormat.OpenXml" Version="2.9.1" />
        <PackageReference Include="DocxToHtml" Version="1.0.4" />
        <PackageReference Include="EPPlus" Version="4.5.3.1" />
        <PackageReference Include="FileHelpers" Version="3.4.0" />
        <PackageReference Include="Mammoth" Version="1.4.0" />
        <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.6.1" />
        <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
        <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.2.3" />
        <PackageReference Include="Microsoft.Azure.Management.AppService.Fluent" Version="1.20.0" />
        <PackageReference Include="Microsoft.Azure.Management.Dns.Fluent" Version="1.20.0" />
        <PackageReference Include="Microsoft.Azure.Management.Fluent" Version="1.20.0" />
        <PackageReference Include="Microsoft.Azure.Search" Version="5.0.3" />
        <PackageReference Include="Microsoft.Graph" Version="1.14.0" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
        <PackageReference Include="Sendgrid" Version="9.10.0" />
        <PackageReference Include="System.Reactive.Linq" Version="4.1.3" />
        <PackageReference Include="System.Threading" Version="4.3.0" />
        <PackageReference Include="unofficial.windowsazure.mediaservices" Version="4.1.0.1" />
        <PackageReference Include="unofficial.windowsazure.mediaservices.extensions" Version="4.1.0.1" />
        <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
    </ItemGroup>

    <ItemGroup>
        <ProjectReference Include="..\xxx.Data\xxx.Data.csproj" />
        <ProjectReference Include="..\TinCan\TinCan.csproj" />
    </ItemGroup>

    <ItemGroup>
        <Compile Update="Properties\Resources.Designer.cs">
            <DesignTime>True</DesignTime>
            <AutoGen>True</AutoGen>
            <DependentUpon>Resources.resx</DependentUpon>
        </Compile>
    </ItemGroup>

    <ItemGroup>
        <EmbeddedResource Update="Properties\Resources.resx">
            <Generator>ResXFileCodeGenerator</Generator>
            <LastGenOutput>Resources.Designer.cs</LastGenOutput>
        </EmbeddedResource>
    </ItemGroup>

</Project>

And the error happens with or without the langversion and nullable referencetypes option. I suspect it's one of the nguet dependencies but not sure which.

And it is now doing it with dotnet build

jaredpar commented 5 years ago

@JohnGalt1717 thanks the stack trace help. Pretty sure that is a separate issue. Asked @cston to take a look at it.

pkindruk commented 5 years ago

@jaredpar same problem here, but completely different environment. @JohnGalt1717 new roslyn compiler seems to be the case for my problem. What version do you fail with? And try finding code pattern methioned in this issue.

My brand new vs2019 failed to build my .NET Framework 4.5 class library saying C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(58,5): error MSB6006: "csc.exe" exited with code -2146232797. Also it gave me some errors in Windows logs

Faulting application name: csc.exe, version: 3.0.19.17001, time stamp: 0xb53a1b95
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0x80131623
Fault offset: 0x00007ffc63c94e0c
Faulting process id: 0x29dc
Faulting application start time: 0x01d4ea31daf070eb
Faulting application path: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn\csc.exe
Faulting module path: unknown
Report Id: 0c5cf8ab-f582-4f0f-84d8-846a634d7ce9
Faulting package full name: 
Faulting package-relative application ID: 
Application: csc.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: System.InvalidOperationException: Unexpected value 'Beq' of type 'System.Reflection.Metadata.ILOpCode'
   at Microsoft.CodeAnalysis.CodeGen.ILOpCodeExtensions.GetLeaveOpcode(ILOpCode opcode)
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BasicBlock.RewriteBranchesAcrossExceptionHandlers()
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RewriteBranchesAcrossExceptionHandlers()
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks()
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize()
   at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
   at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.Generate(Int32& asyncCatchHandlerOffset, ImmutableArray`1& asyncYieldPoints, ImmutableArray`1& asyncResumePoints)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 closureDebugInfo, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, Boolean emitTestCoverageData, ImmutableArray`1 dynamicAnalysisSpans)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass21_0.<CompileNamedTypeAsTask>b__0()
Stack:
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.CodeAnalysis.FatalError.ReportUnlessCanceled(System.Exception)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass21_0.<CompileNamedTypeAsTask>b__0()
   at Microsoft.CodeAnalysis.CodeGen.ILOpCodeExtensions.GetLeaveOpcode(System.Reflection.Metadata.ILOpCode)
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+BasicBlock.RewriteBranchesAcrossExceptionHandlers()
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RewriteBranchesAcrossExceptionHandlers()
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks()
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize()
   at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
   at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.Generate(Int32 ByRef, System.Collections.Immutable.ImmutableArray`1<Int32> ByRef, System.Collections.Immutable.ImmutableArray`1<Int32> ByRef)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Int32, Microsoft.CodeAnalysis.CSharp.BoundStatement, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.LambdaDebugInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.ClosureDebugInfo>, Microsoft.CodeAnalysis.CSharp.StateMachineTypeSymbol, Microsoft.CodeAnalysis.CodeGen.VariableSlotAllocator, Microsoft.CodeAnalysis.DiagnosticBag, Microsoft.CodeAnalysis.CodeGen.DebugDocumentProvider, Microsoft.CodeAnalysis.CSharp.ImportChain, Boolean, Boolean, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.SourceSpan>)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(Microsoft.CodeAnalysis.CSharp.TypeCompilationState)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass21_0.<CompileNamedTypeAsTask>b__0()
   at Roslyn.Utilities.UICultureUtilities+<>c__DisplayClass5_0.<WithCurrentUICulture>b__0()
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Then I opened my sandbox console app (.NET Framework 4.6.1) and used code issue starter provided. Same result. I went to the project originally failing and found code like this(I omitted all business logic):

class A
{
    private async Task DoSmth()
    {
        try
        {
            try
            {
                //1
                return;
            }
            finally
            {
                //2
                await Task.CompletedTask;
            }
        }
        catch { }
        finally
        {
            //3
            await Task.CompletedTask;
        }
    }
}

Removing any of numbered lines makes code compile.

My primary project is still compiling with vs2017. So I put that simplified class above in the console app right next to plain Main method and tried to compile on vs2017 (success) and vs2019 (failure). All projects were created under vs2017 and opened in vs2019 if that matters.

And last thing csc.exe versions:

c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn>csc -version
2.10.0.0 (b9fb1610)

c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn>csc -version
3.0.19.17001 (1deafee3)
gingters commented 5 years ago

Hello. I also see that issue. It compiles fine in VS 2017 and not in VS 2019.

This is our solution: https://github.com/thinktecture/relayserver/tree/2.2.0 In the project OnPremiseConnector in the class RelayServerConnection we have a try -> try -> finally -> await constellation that might be another version of #34720.

This issue is blocking updating to VS 2019.

cston commented 5 years ago

@gingters, #34791 should fix the code gen issue with an await in a nested finally clause. In the meantime, before the fix is available, are you able to get unblocked by extracting the nested try/finally to a separate method or local function?

springy76 commented 5 years ago

Starting with VS2019 PREVIEW 16.3.0 Preview X (1..4) I get this exact message for one (large!) project in a solution containing 132 projects. It's the second-important project in this solution :(

Using VS2019 RELEASE 16.2.X everything is ok. I fear when 16.3 will become the new release this bug still will be present. What can I do to narrow this problem down?

C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error MSB6006: "csc.exe" exited with code -2146232797.
cston commented 5 years ago

@springy76, thanks for reporting the latest issue. Is there a stack trace for the failure in csc.exe in the Windows event log? If so, please share the stack trace if you're comfortable doing so. Thanks.

springy76 commented 5 years ago

@cston I found the event log later and then created a new issue #38725