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 on switch with type pattern matching and async in release mode. #52639

Closed
Banner-Keith opened this issue Apr 14, 2021 · 1 comment · Fixed by #55922
Assignees
Milestone

Comments

@Banner-Keith
Copy link

Version Used:
Visual Studio 16.8.5 & 16.9.4

Steps to Reproduce:

  1. Attempt to compile the code in Debug mode. Works fine.
  2. Attempt to compile the code in Release mode. Error thrown.

This code can be pasted into any .net framework controller. I am using .net 4.8

public async Task<ActionResult> Test(MyBaseClass model)
{
	switch (model)
	{
		case FirstImplementation firstImplementation:
			firstImplementation.MyString1 = await Task.FromResult("test");
			break;
		default:
			throw new ArgumentOutOfRangeException(nameof(model));
	}

	switch (model)
	{
		case FirstImplementation firstImplementation:
			await Task.FromResult(1);
			return PartialView("View", firstImplementation);
		default:
			throw new ArgumentOutOfRangeException(nameof(model));
	}
}

I just pasted these classes inside of the namespace section on the controller for my example.

public abstract class MyBaseClass
{
	public string MyString { get; set; }
}

public class FirstImplementation : MyBaseClass
{
	public string MyString1 { get; set; }
}

public class SecondImplementation : MyBaseClass
{
	public string MyString2 { get; set; }
}

Expected Behavior:
Successful build

Actual Behavior:
Compiler error

This seems to be a very specific scenario where a property is changed after an await and then another switch later in the same method has something async happening within it.

I understand this is a big edge case, but wanted to make sure it was reported.

@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 14, 2021
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 15, 2021
@jaredpar jaredpar added this to the 16.10 milestone Apr 15, 2021
@RikkiGibson
Copy link
Contributor

RikkiGibson commented Apr 16, 2021

Minimal repro (edit: simplified)

using System.Threading.Tasks;

class C
{
    string F;

    async Task<C> Test(C c)
    {
        c.F = await Task.FromResult("a");

        switch (c)
        {
            case C c1:
                await Task.FromResult(1);
                return c1;
        }

        return null;
    }
}

Produces this stack trace in release mode:

Process terminated. System.IndexOutOfRangeException: Index was outside the bounds of the array. [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Collections.Immutable.ImmutableArray`1.Builder.set_Item(Int32 index, T value) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeInfo.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ScopeInfo.GetHoistedLocalScopes[TScopeInfo](ArrayBuilder`1 result, Builder scopes) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeInfo.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ScopeInfo.GetHoistedLocalScopes[TScopeInfo](ArrayBuilder`1 result, Builder scopes) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ExceptionHandlerContainerScope.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ScopeInfo.GetHoistedLocalScopes[TScopeInfo](ArrayBuilder`1 result, Builder scopes) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeInfo.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ScopeInfo.GetHoistedLocalScopes[TScopeInfo](ArrayBuilder`1 result, Builder scopes) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeInfo.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeManager.GetHoistedLocalScopes() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.GetHoistedLocalScopes() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   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, AsyncForwardEntryPoint entryPointOpt) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Environment.FailFast(System.String, System.Exception) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.FatalError.Report(System.Exception, System.Action`1<System.Exception>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.FatalError.ReportAndPropagateUnlessCanceled(System.Exception) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Collections.Immutable.ImmutableArray`1+Builder[[Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope, Microsoft.CodeAnalysis, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].set_Item(Int32, Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+LocalScopeInfo.GetHoistedLocalScopes(Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+ScopeInfo.GetHoistedLocalScopes[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>, Builder<System.__Canon>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+LocalScopeInfo.GetHoistedLocalScopes(Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+ScopeInfo.GetHoistedLocalScopes[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>, Builder<System.__Canon>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+ExceptionHandlerContainerScope.GetHoistedLocalScopes(Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+ScopeInfo.GetHoistedLocalScopes[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>, Builder<System.__Canon>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+LocalScopeInfo.GetHoistedLocalScopes(Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+ScopeInfo.GetHoistedLocalScopes[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>, Builder<System.__Canon>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+LocalScopeInfo.GetHoistedLocalScopes(Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<Microsoft.CodeAnalysis.Debugging.StateMachineHoistedLocalScope>) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder+LocalScopeManager.GetHoistedLocalScopes() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.GetHoistedLocalScopes() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   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>, AsyncForwardEntryPoint) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(Microsoft.CodeAnalysis.CSharp.TypeCompilationState) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Roslyn.Utilities.UICultureUtilities+<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Threading.Tasks.Task.InnerInvoke() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Threading.Tasks.Task+<>c.<.cctor>b__277_0(System.Object) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Threading.Tasks.Task.ExecuteEntryUnsafe(System.Threading.Thread) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Threading.Tasks.Task.ExecuteFromThreadPool(System.Threading.Thread) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Threading.ThreadPoolWorkQueue.Dispatch() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
System.IndexOutOfRangeException: Index was outside the bounds of the array. [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at System.Collections.Immutable.ImmutableArray`1.Builder.set_Item(Int32 index, T value) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeInfo.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ScopeInfo.GetHoistedLocalScopes[TScopeInfo](ArrayBuilder`1 result, Builder scopes) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeInfo.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ScopeInfo.GetHoistedLocalScopes[TScopeInfo](ArrayBuilder`1 result, Builder scopes) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ExceptionHandlerContainerScope.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ScopeInfo.GetHoistedLocalScopes[TScopeInfo](ArrayBuilder`1 result, Builder scopes) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeInfo.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ScopeInfo.GetHoistedLocalScopes[TScopeInfo](ArrayBuilder`1 result, Builder scopes) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeInfo.GetHoistedLocalScopes(ArrayBuilder`1 result) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.LocalScopeManager.GetHoistedLocalScopes() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CodeGen.ILBuilder.GetHoistedLocalScopes() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   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, AsyncForwardEntryPoint entryPointOpt) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) [C:\Users\rikki\src\releasecrash\releasecrash.csproj]
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\Users\rikki\src\releasecrash\releasecrash.csproj]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants