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

[dotnet-sdk-9.0.100-preview.3.24175.24] Microsoft.CSharp.Core.targets thrown errors when using "dotnet build" #72753

Closed
Junjun-zhao opened this issue Mar 27, 2024 · 6 comments
Assignees
Milestone

Comments

@Junjun-zhao
Copy link
Member

Junjun-zhao commented Mar 27, 2024

Application Name: Dapper
OS: Windows 10 21H2
CPU: X64
.NET Build Number: dotnet-sdk-9.0.100-preview.3.24175.24
App Source Location checking from: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2010200
Github Link:
https://github.com/DapperLib/Dapper

Verify Scenarios:

  1. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.3.24175.24 + default target .NET 8.0: Fail
  2. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.2.24157.14 + default target .NET 8.0: Pass
  3. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.1.24076.20 + default target .NET 8.0: Pass
  4. Windows10 21h2 x64 + dotnet-sdk-8.0.203-win-x64 + default target .NET 8.0 : Pass

Description:
When building Dapper app with dotnet-sdk-9.0.100-preview.3.24175.24, the build failed with errors come from Microsoft.CSharp.Core.targets. And this issue occurs when using "dotnet build" command. If we use Visual Studio or MSBuild command, the build can successful.

Minimal Repro steps (Demo attached):
DotNetBuildIssue.zip

The machine has dotnet-sdk-9.0.100-preview.3.24175.24 installed.

  1. Create 8.0 Console App.
  2. Install Nuget Package: xunit.assert.
  3. Add below code to Program.cs.
using System.Data;
using System.Data.Common;
using Xunit;

internal class Program
{
    private static void Main(string[] args)
    {  }
    public async Task Test(DbConnection connection)
    {
        await using (await connection.QuerySingle())
        {
            var ex = await Assert.ThrowsAnyAsync<Exception>(async () =>{ });
            Assert.True(ex is OperationCanceledException or DbException { Message: "" });
        }
    }
}
public static partial class SqlMapper
{
    public static dynamic QuerySingle(this IDbConnection cnn)
    {
        return null;
    }
}
  1. Open command prompt windows and navigate to this project file folder.

  2. Run "dotnet build".

Expected Result:
"dotnet build" command build project successfully.

Actual Result:
Build failed with errors come from Microsoft.CSharp.Core.targets.

Detailed errors:(Or Please refer to more details from the attached binlog from https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2010200)

E:\Demos\DotNetBuildIssue\DotNetBuildIssue>dotnet build
Restore complete (0.6s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  DotNetBuildIssue failed with errors (6.2s)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error : Process terminated. System.NullReferenceException: Object reference not set to an instance of an object.
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BlockedBranchDestinationSlow(ExceptionHandlerScope destHandler, ExceptionHandlerScope srcHandler)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.MarkReachableFromBranch(ArrayBuilder`1 reachableBlocks, BasicBlock block)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.MarkReachableBlocks()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.Generate(Int32& asyncCatchHandlerOffset, ImmutableArray`1& asyncYieldPoints, ImmutableArray`1& asyncResumePoints, Boolean& hasStackAlloc)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    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)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Environment.FailFast(System.String, System.Exception)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception, Microsoft.CodeAnalysis.ErrorReporting.ErrorSeverity, Boolean)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.ErrorReporting.FatalError.ReportAndPropagateUnlessCanceled(System.Exception, Microsoft.CodeAnalysis.ErrorReporting.ErrorSeverity)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Runtime.EH.FindFirstPassHandler(System.Object, UInt32, System.Runtime.StackFrameIterator ByRef, UInt32 ByRef, Byte* ByRef)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Runtime.EH.RhThrowHwEx(UInt32, ExInfo ByRef)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BlockedBranchDestinationSlow(ExceptionHandlerScope, ExceptionHandlerScope)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.MarkReachableFromBranch(Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<BasicBlock>, BasicBlock)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.MarkReachableBlocks()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,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, Boolean ByRef)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,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.Emit.EncLambdaInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.LambdaRuntimeRudeEditInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.Emit.EncClosureInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.StateMachineStateDebugInfo>, Microsoft.CodeAnalysis.CSharp.StateMachineTypeSymbol, Microsoft.CodeAnalysis.CodeGen.VariableSlotAllocator, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag, Microsoft.CodeAnalysis.CodeGen.DebugDocumentProvider, Microsoft.CodeAnalysis.CSharp.ImportChain, Boolean, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.SourceSpan>, AsyncForwardEntryPoint)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(Microsoft.CodeAnalysis.CSharp.TypeCompilationState)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Threading.ThreadPoolWorkQueue.Dispatch()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error : System.NullReferenceException: Object reference not set to an instance of an object.
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BlockedBranchDestinationSlow(ExceptionHandlerScope destHandler, ExceptionHandlerScope srcHandler)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.MarkReachableFromBranch(ArrayBuilder`1 reachableBlocks, BasicBlock block)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.MarkReachableBlocks()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.Generate(Int32& asyncCatchHandlerOffset, ImmutableArray`1& asyncYieldPoints, ImmutableArray`1& asyncResumePoints, Boolean& hasStackAlloc)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    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)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
    C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()

@dotnet-actwx-bot @dotnet/compat

@Junjun-zhao
Copy link
Member Author

@jcouv Could you help check this issue and confirm whether it is a blocker for .NET 9.0 Preview3 validation? Please help move to the right area if it was assigned incorrect. Thanks.

@jcouv jcouv added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 1, 2024
@jcouv
Copy link
Member

jcouv commented Apr 1, 2024

Likely a regression from #72598

@jcouv
Copy link
Member

jcouv commented Apr 1, 2024

I've narrowed down a repro, but it doesn't seem a regression of the await using change I suspected. Will investigate further.

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72753")]
        public void TODO2_3()
        {
            var src = """
using System;
using System.Threading.Tasks;

internal class Program
{
    public async Task Test()
    {
        try
        {
            var ex = new Exception();
            _ = ex is OperationCanceledException or MyException { Message: "" };
        }
        finally
        {
            await Task.CompletedTask;
        }
    }
}
class MyException : Exception
{
    public string Message => "";
}
""";
            var comp = CreateCompilation(src, targetFramework: TargetFramework.Net80);
            comp.VerifyEmitDiagnostics();
            //  System.NullReferenceException : Object reference not set to an instance of an object.
            // Stack Trace: 
            //ILBuilder.BlockedBranchDestinationSlow(ExceptionHandlerScope destHandler, ExceptionHandlerScope srcHandler) line 400
            //ILBuilder.MarkReachableFromBranch(ArrayBuilder`1 reachableBlocks, BasicBlock block) line 345
            //ILBuilder.MarkReachableFrom(ArrayBuilder`1 reachableBlocks, BasicBlock block) line 329
        }

@jcouv jcouv modified the milestones: 17.11, 17.10 Apr 1, 2024
@jcouv
Copy link
Member

jcouv commented Apr 1, 2024

Looks like a regression from #72273 (the test no longer crashes after reverting that change)

@jcouv jcouv removed their assignment Apr 1, 2024
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 1, 2024
@jcouv
Copy link
Member

jcouv commented Apr 1, 2024

Filed devdiv issue for QB mode: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2014915

@Junjun-zhao
Copy link
Member Author

Verified this issue with the latest build 9.0.100-preview.3.24204.13, it has been fixed. Hence closing it. Thank you.

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

3 participants