microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.12k stars 93 forks source link

CsWin32 analyzer crashes the Code Analysis service in VS 2022 #615

Closed jlaanstra closed 2 years ago

jlaanstra commented 2 years ago

Actual behavior

ServiceHub.RoslynCodeAnalysisService.exe randomly crashes during development:

Application: ServiceHub.RoslynCodeAnalysisService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
   at System.Text.StringBuilder.Append(System.String)
   at System.IO.StringWriter.Write(System.String)
   at Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxToken.WriteTokenTo(System.IO.TextWriter, Boolean, Boolean)
   at Microsoft.CodeAnalysis.GreenNode.<WriteTo>g__processStack|104_0(System.IO.TextWriter, Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1<System.ValueTuple`3<Microsoft.CodeAnalysis.GreenNode,Boolean,Boolean>>)
   at Microsoft.CodeAnalysis.GreenNode.WriteTo(System.IO.TextWriter, Boolean, Boolean)
   at Microsoft.CodeAnalysis.GreenNode.ToString()
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.PointerTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.Generator.CreateParameter(Microsoft.Windows.CsWin32.TypeHandleInfo, System.Reflection.Metadata.Parameter, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass265_0.<CreateParameterList>b__1(System.Reflection.Metadata.Parameter)
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Reflection.Metadata.Parameter, System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Linq.Buffer`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at Microsoft.Windows.CsWin32.Generator.CreateParameterList(System.Reflection.Metadata.MethodDefinition, System.Reflection.Metadata.MethodSignature`1<Microsoft.Windows.CsWin32.TypeHandleInfo>, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterfaceAsInterface(System.Reflection.Metadata.TypeDefinition, System.Collections.Generic.Stack`1<Microsoft.Windows.CsWin32.QualifiedTypeDefinitionHandle>)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterface(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass161_0.<RequestInteropType>b__0()
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerateType(System.Reflection.Metadata.TypeDefinitionHandle, Boolean, System.Action)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeReferenceHandle, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.RequestTypeGeneration(Microsoft.Windows.CsWin32.Generator, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.PointerTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.Generator.CreateParameter(Microsoft.Windows.CsWin32.TypeHandleInfo, System.Reflection.Metadata.Parameter, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass265_0.<CreateParameterList>b__1(System.Reflection.Metadata.Parameter)
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Reflection.Metadata.Parameter, System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Linq.Buffer`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at Microsoft.Windows.CsWin32.Generator.CreateParameterList(System.Reflection.Metadata.MethodDefinition, System.Reflection.Metadata.MethodSignature`1<Microsoft.Windows.CsWin32.TypeHandleInfo>, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterfaceAsInterface(System.Reflection.Metadata.TypeDefinition, System.Collections.Generic.Stack`1<Microsoft.Windows.CsWin32.QualifiedTypeDefinitionHandle>)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterface(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass161_0.<RequestInteropType>b__0()
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerateType(System.Reflection.Metadata.TypeDefinitionHandle, Boolean, System.Action)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeReferenceHandle, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.RequestTypeGeneration(Microsoft.Windows.CsWin32.Generator, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.PointerTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.Generator.CreateParameter(Microsoft.Windows.CsWin32.TypeHandleInfo, System.Reflection.Metadata.Parameter, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass265_0.<CreateParameterList>b__1(System.Reflection.Metadata.Parameter)
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Reflection.Metadata.Parameter, System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Linq.Buffer`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at Microsoft.Windows.CsWin32.Generator.CreateParameterList(System.Reflection.Metadata.MethodDefinition, System.Reflection.Metadata.MethodSignature`1<Microsoft.Windows.CsWin32.TypeHandleInfo>, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterfaceAsStruct(System.Reflection.Metadata.TypeDefinitionHandle, System.Collections.Generic.Stack`1<Microsoft.Windows.CsWin32.QualifiedTypeDefinitionHandle>, Context)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterface(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass161_0.<RequestInteropType>b__0()
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerateType(System.Reflection.Metadata.TypeDefinitionHandle, Boolean, System.Action)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeReferenceHandle, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.RequestTypeGeneration(Microsoft.Windows.CsWin32.Generator, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.Generator.DeclareStruct(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass161_0.<RequestInteropType>b__0()
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerateType(System.Reflection.Metadata.TypeDefinitionHandle, Boolean, System.Action)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeReferenceHandle, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.RequestTypeGeneration(Microsoft.Windows.CsWin32.Generator, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.Generator.DeclareStruct(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass161_0.<RequestInteropType>b__0()
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerateType(System.Reflection.Metadata.TypeDefinitionHandle, Boolean, System.Action)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeReferenceHandle, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.RequestTypeGeneration(Microsoft.Windows.CsWin32.Generator, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.PointerTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.Generator.CreateParameter(Microsoft.Windows.CsWin32.TypeHandleInfo, System.Reflection.Metadata.Parameter, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass265_0.<CreateParameterList>b__1(System.Reflection.Metadata.Parameter)
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Reflection.Metadata.Parameter, System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Linq.Buffer`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at Microsoft.Windows.CsWin32.Generator.CreateParameterList(System.Reflection.Metadata.MethodDefinition, System.Reflection.Metadata.MethodSignature`1<Microsoft.Windows.CsWin32.TypeHandleInfo>, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterfaceAsInterface(System.Reflection.Metadata.TypeDefinition, System.Collections.Generic.Stack`1<Microsoft.Windows.CsWin32.QualifiedTypeDefinitionHandle>)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterface(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass161_0.<RequestInteropType>b__0()
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerateType(System.Reflection.Metadata.TypeDefinitionHandle, Boolean, System.Action)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeReferenceHandle, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.RequestTypeGeneration(Microsoft.Windows.CsWin32.Generator, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.PointerTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.Generator.CreateParameter(Microsoft.Windows.CsWin32.TypeHandleInfo, System.Reflection.Metadata.Parameter, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass265_0.<CreateParameterList>b__1(System.Reflection.Metadata.Parameter)
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Reflection.Metadata.Parameter, System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Linq.Buffer`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at Microsoft.Windows.CsWin32.Generator.CreateParameterList(System.Reflection.Metadata.MethodDefinition, System.Reflection.Metadata.MethodSignature`1<Microsoft.Windows.CsWin32.TypeHandleInfo>, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterfaceAsInterface(System.Reflection.Metadata.TypeDefinition, System.Collections.Generic.Stack`1<Microsoft.Windows.CsWin32.QualifiedTypeDefinitionHandle>)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterface(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass161_0.<RequestInteropType>b__0()
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerateType(System.Reflection.Metadata.TypeDefinitionHandle, Boolean, System.Action)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.RequestTypeGeneration(Microsoft.Windows.CsWin32.Generator, Context)
   at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.PointerTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, System.Nullable`1<System.Reflection.Metadata.CustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
   at Microsoft.Windows.CsWin32.Generator.CreateParameter(Microsoft.Windows.CsWin32.TypeHandleInfo, System.Reflection.Metadata.Parameter, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass265_0.<CreateParameterList>b__1(System.Reflection.Metadata.Parameter)
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Reflection.Metadata.Parameter, System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Linq.Buffer`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at Microsoft.Windows.CsWin32.Generator.CreateParameterList(System.Reflection.Metadata.MethodDefinition, System.Reflection.Metadata.MethodSignature`1<Microsoft.Windows.CsWin32.TypeHandleInfo>, Microsoft.Windows.CsWin32.TypeSyntaxSettings)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterfaceAsInterface(System.Reflection.Metadata.TypeDefinition, System.Collections.Generic.Stack`1<Microsoft.Windows.CsWin32.QualifiedTypeDefinitionHandle>)
   at Microsoft.Windows.CsWin32.Generator.DeclareInterface(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropTypeHelper(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+<>c__DisplayClass161_0.<RequestInteropType>b__0()
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerateType(System.Reflection.Metadata.TypeDefinitionHandle, Boolean, System.Action)
   at Microsoft.Windows.CsWin32.Generator.RequestInteropType(System.Reflection.Metadata.TypeDefinitionHandle, Context)
   at Microsoft.Windows.CsWin32.Generator+GeneratedCode.GenerationTransaction(System.Action)
   at Microsoft.Windows.CsWin32.Generator.TryGenerateType(System.String, System.Collections.Generic.IReadOnlyList`1<System.String> ByRef)
   at Microsoft.Windows.CsWin32.Generator.TryGenerate(System.String, System.Collections.Generic.IReadOnlyList`1<System.String> ByRef, System.Threading.CancellationToken)
   at Microsoft.Windows.CsWin32.SourceGenerator.Execute(Microsoft.CodeAnalysis.GeneratorExecutionContext)
   at Microsoft.CodeAnalysis.SourceGeneratorAdaptor.<Initialize>b__5_5(Microsoft.CodeAnalysis.SourceProductionContext, GeneratorContextBuilder)
   at Microsoft.CodeAnalysis.UserFunctionExtensions+<>c__DisplayClass3_0`2[[Microsoft.CodeAnalysis.SourceProductionContext, Microsoft.CodeAnalysis, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<WrapUserAction>b__0(Microsoft.CodeAnalysis.SourceProductionContext, System.__Canon, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SourceOutputNode`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].UpdateStateTable(Builder, Microsoft.CodeAnalysis.NodeStateTable`1<System.ValueTuple`2<System.Collections.Generic.IEnumerable`1<Microsoft.CodeAnalysis.GeneratedSourceText>,System.Collections.Generic.IEnumerable`1<Microsoft.CodeAnalysis.Diagnostic>>>, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.DriverStateTable+Builder.GetLatestStateTableForNode[[System.ValueTuple`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](Microsoft.CodeAnalysis.IIncrementalGeneratorNode`1<System.ValueTuple`2<System.__Canon,System.__Canon>>)
   at Microsoft.CodeAnalysis.SourceOutputNode`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].AppendOutputs(Microsoft.CodeAnalysis.IncrementalExecutionContext, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.GeneratorDriver.UpdateOutputs(System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.IIncrementalGeneratorOutputNode>, Microsoft.CodeAnalysis.IncrementalGeneratorOutputKind, Builder, System.Threading.CancellationToken, Builder)
   at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Microsoft.CodeAnalysis.Compilation, Microsoft.CodeAnalysis.DiagnosticBag, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Microsoft.CodeAnalysis.Compilation, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<FinalizeCompilationAsync>d__39.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+CompilationInfo, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<FinalizeCompilationAsync>d__39, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<FinalizeCompilationAsync>d__39 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.FinalizeCompilationAsync(Microsoft.CodeAnalysis.SolutionState, Microsoft.CodeAnalysis.Compilation, CompilationTrackerGeneratorInfo, Microsoft.CodeAnalysis.Compilation, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<BuildFinalStateFromInProgressStateAsync>d__36.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+CompilationInfo, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<BuildFinalStateFromInProgressStateAsync>d__36, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<BuildFinalStateFromInProgressStateAsync>d__36 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.BuildFinalStateFromInProgressStateAsync(Microsoft.CodeAnalysis.SolutionState, InProgressState, Microsoft.CodeAnalysis.Compilation, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<BuildCompilationInfoAsync>d__32.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+CompilationInfo, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<BuildCompilationInfoAsync>d__32, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<BuildCompilationInfoAsync>d__32 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.BuildCompilationInfoAsync(Microsoft.CodeAnalysis.SolutionState, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<GetOrBuildCompilationInfoAsync>d__31.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+CompilationInfo, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<GetOrBuildCompilationInfoAsync>d__31, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<GetOrBuildCompilationInfoAsync>d__31 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.GetOrBuildCompilationInfoAsync(Microsoft.CodeAnalysis.SolutionState, Boolean, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<GetCompilationSlowAsync>d__29.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<GetCompilationSlowAsync>d__29, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<GetCompilationSlowAsync>d__29 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.GetCompilationSlowAsync(Microsoft.CodeAnalysis.SolutionState, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.GetCompilationAsync(Microsoft.CodeAnalysis.SolutionState, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+<GetMetadataReferenceAsync>d__152.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[Microsoft.CodeAnalysis.SolutionState+<GetMetadataReferenceAsync>d__152, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<GetMetadataReferenceAsync>d__152 ByRef)
   at Microsoft.CodeAnalysis.SolutionState.GetMetadataReferenceAsync(ICompilationTracker, Microsoft.CodeAnalysis.ProjectState, Microsoft.CodeAnalysis.ProjectReference, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState.GetMetadataReferenceAsync(Microsoft.CodeAnalysis.ProjectReference, Microsoft.CodeAnalysis.ProjectState, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<FinalizeCompilationAsync>d__39.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+CompilationInfo, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<FinalizeCompilationAsync>d__39, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<FinalizeCompilationAsync>d__39 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.FinalizeCompilationAsync(Microsoft.CodeAnalysis.SolutionState, Microsoft.CodeAnalysis.Compilation, CompilationTrackerGeneratorInfo, Microsoft.CodeAnalysis.Compilation, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<BuildCompilationInfoAsync>d__32.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+CompilationInfo, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<BuildCompilationInfoAsync>d__32, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<BuildCompilationInfoAsync>d__32 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.BuildCompilationInfoAsync(Microsoft.CodeAnalysis.SolutionState, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<GetOrBuildCompilationInfoAsync>d__31.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+CompilationInfo, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<GetOrBuildCompilationInfoAsync>d__31, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<GetOrBuildCompilationInfoAsync>d__31 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.GetOrBuildCompilationInfoAsync(Microsoft.CodeAnalysis.SolutionState, Boolean, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<GetCompilationSlowAsync>d__29.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<GetCompilationSlowAsync>d__29, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<GetCompilationSlowAsync>d__29 ByRef)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.GetCompilationSlowAsync(Microsoft.CodeAnalysis.SolutionState, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker.GetCompilationAsync(Microsoft.CodeAnalysis.SolutionState, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+<GetMetadataReferenceAsync>d__152.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[Microsoft.CodeAnalysis.SolutionState+<GetMetadataReferenceAsync>d__152, Microsoft.CodeAnalysis.Workspaces, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<GetMetadataReferenceAsync>d__152 ByRef)
   at Microsoft.CodeAnalysis.SolutionState.GetMetadataReferenceAsync(ICompilationTracker, Microsoft.CodeAnalysis.ProjectState, Microsoft.CodeAnalysis.ProjectReference, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState.GetMetadataReferenceAsync(Microsoft.CodeAnalysis.ProjectReference, Microsoft.CodeAnalysis.ProjectState, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionState+CompilationTracker+<FinalizeCompilationAsync>d__39.MoveNext()

The remainder of the message was truncated.

Expected behavior

No crash.

Repro steps

  1. NativeMethods.txt content:

    I have multiple projects with different content of NativeMethods.txt, hopefully the stack is helpful.
  2. NativeMethods.json content (if present):

  3. Any of your own code that should be shared?

Context

AArnott commented 2 years ago

Thanks for reporting this. This looks like memory corruption. I don't think CsWin32 could be responsible for it though. Can you use Report a Problem in VS and repro it under the recorder so that a heap dump of the process can be shared with Microsoft and they can investigate? I wonder if another roslyn extension in that process is corrupting the memory.