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

Strange Exceptions During Binding #74574

Closed
JasonBock opened this issue Jul 26, 2024 · 3 comments
Closed

Strange Exceptions During Binding #74574

JasonBock opened this issue Jul 26, 2024 · 3 comments
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@JasonBock
Copy link

JasonBock commented Jul 26, 2024

Version Used:

.NET 9 - 9.0.100-preview.6.24328.19
Microsoft.CodeAnalysis.CSharp - 4.11.0-2.final
VS 2022 Preview 5 (17.11.0)

Steps to Reproduce:

  1. Pull this branch: https://github.com/JasonBock/Rocks/tree/9_0_0 (specifically at this point)
  2. Open the Rocks.sln file, and make sure Rocks.CodeGenerationTest is the startup project. Also, make sure TestWithTypes() is the call that happens in Program.cs:

image

  1. Run the application.

Expected Behavior:
The application runs. Note that the application may report errors with a bunch of red text when it finishes, but that is not unexpected.

Actual Behavior:
Occasionally, I'm seeing random exceptions from the Compiler API. Unfortunately, I can't reproduce the error or when it occurs, but here are two stack traces that I've seen when things fail.

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.Binder.BindConstructorInitializerCoreContinued(Boolean found, ArgumentListSyntax initializerArgumentListOpt, MethodSymbol constructor, AnalyzedArguments analyzedArguments, TypeSymbol constructorReturnType, NamedTypeSymbol initializerType, Boolean isBaseConstructorInitializer, CSharpSyntaxNode nonNullSyntax, Location errorLocation, Boolean enableCallerInfo, MemberResolutionResult`1 memberResolutionResult, ImmutableArray`1 candidateConstructors, CompoundUseSiteInfo`1& overloadResolutionUseSiteInfo, BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindConstructorInitializerCore(ArgumentListSyntax initializerArgumentListOpt, MethodSymbol constructor, BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindImplicitConstructorInitializer(MethodSymbol constructor, BindingDiagnosticBag diagnostics, CSharpCompilation compilation)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.BindMethodBody(MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, Boolean includeInitializersInBody, BoundNode initializersBody, Boolean reportNullableDiagnostics, ImportChain& importChain, Boolean& originalBodyNested, Boolean& prependedDefaultValueTypeConstructorInitializer, InitialState& forSemanticModel)
   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()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Compilation.Emit(Stream peStream, Stream metadataPEStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, RebuildData rebuildData, CompilationTestData testData, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Compilation.Emit(Stream peStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, Stream metadataPEStream, RebuildData rebuildData, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Compilation.Emit(Stream peStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, Stream metadataPEStream, CancellationToken cancellationToken)
   at Rocks.CodeGenerationTest.TestGenerator.Generate(IIncrementalGenerator generator, Type[] targetTypes, Type[] typesToLoadAssembliesFrom, String[] aliases, BuildType buildType) in C:\Users\jason\source\repos\JasonBock\Rocks\src\Rocks.CodeGenerationTest\TestGenerator.cs:line 201
   at Program.<<Main>$>g__TestWithTypes|0_4() in C:\Users\jason\source\repos\JasonBock\Rocks\src\Rocks.CodeGenerationTest\Program.cs:line 255
   at Program.<Main>$(String[] args) in C:\Users\jason\source\repos\JasonBock\Rocks\src\Rocks.CodeGenerationTest\Program.cs:line 18
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Microsoft.CodeAnalysis.CSharp.Binder.BindConstructorInitializerCoreContinued(Boolean, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Microsoft.CodeAnalysis.CSharp.AnalyzedArguments, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol, Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol, Boolean, Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, Microsoft.CodeAnalysis.Location, Boolean, Microsoft.CodeAnalysis.CSharp.MemberResolutionResult`1<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol>, Microsoft.CodeAnalysis.CompoundUseSiteInfo`1<Microsoft.CodeAnalysis.CSharp.Symbols.AssemblySymbol> ByRef, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindConstructorInitializerCore(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindConstructorBody(Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindMethodBody(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindWithLambdaBindingCountDiagnostics[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon, System.__Canon, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag, System.Func`5<Microsoft.CodeAnalysis.CSharp.Binder,System.__Canon,System.__Canon,Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag,System.__Canon>)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.BindMethodBody(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Microsoft.CodeAnalysis.CSharp.TypeCompilationState, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag, Boolean, Microsoft.CodeAnalysis.CSharp.BoundNode, Boolean, Microsoft.CodeAnalysis.CSharp.ImportChain ByRef, Boolean ByRef, Boolean ByRef, InitialState ByRef)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Int32, ProcessedFieldInitializers ByRef, Microsoft.CodeAnalysis.CSharp.SynthesizedSubmissionFields, Microsoft.CodeAnalysis.CSharp.TypeCompilationState)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol)
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

I've never had any kinds of exceptions like this with my test application before. Only when I started moving to doing some work with .NET 9 and VS 2022 preview versions am I seeing these random issues.

I wish I could give you something more repeatable. Sometimes the app finishes as expected. But I am seeing exceptions like these.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 26, 2024
@JasonBock
Copy link
Author

Looks related to this, which may be fixed by this?

@jaredpar
Copy link
Member

jaredpar commented Aug 5, 2024

Think it's likely that it's the same runtime issue. Going to close for now. If it's tsill happening in .NET 9 RC1 we can re-evaluate.

@jaredpar jaredpar closed this as completed Aug 5, 2024
@JasonBock
Copy link
Author

FWIW I updated to .NET 9 Preview 7, and have run my test program numerous times with no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants