我正在尝试使用 Roslyn 解析 VB.Net 代码,但它不断抛出InvalidProgramException
(Jit 编译器遇到限制..)。类似的代码与 C# 完美配合。
这是我的代码:
var source = "Public Module Module1 \r\n Public Sub X() \r\n End Sub \r\n End Module";
var syntaxTree = Roslyn.Compilers.VisualBasic.SyntaxTree.ParseText(source);
var compilation = Roslyn.Compilers.VisualBasic.Compilation.Create("MyCompilation", syntaxTrees: new[] {syntaxTree});
var semanticModel = compilation.GetSemanticModel(syntaxTree);
在最后一行抛出异常。
更新这是堆栈跟踪:
System.InvalidProgramException: JIT Compiler encountered an internal limitation.
HResult: -2146233030
в Roslyn.Compilers.VisualBasic.SeparatedSyntaxList`1..ctor(SyntaxNode node, Int32 index)
в Roslyn.Compilers.VisualBasic.CompilationUnitSyntax.get_Members()
в Roslyn.Compilers.VisualBasic.DeclarationTreeBuilder.VisitCompilationUnit(CompilationUnitSyntax node)
в Roslyn.Compilers.VisualBasic.CompilationUnitSyntax.Accept[TResult](SyntaxVisitor`1 visitor)
в Roslyn.Compilers.VisualBasic.SyntaxVisitor`1.Visit(SyntaxNode node)
в Roslyn.Compilers.VisualBasic.DeclarationTreeBuilder.ForDeclaration(SyntaxNode node)
в Roslyn.Compilers.VisualBasic.DeclarationTreeBuilder.ForTree(SyntaxTree tree, ReadOnlyArray`1 rootNamespace, String scriptClassName, Boolean isSubmission)
в Roslyn.Compilers.VisualBasic.Compilation.ForTree(SyntaxTree tree, CompilationOptions options, Boolean isSubmission)
в Roslyn.Compilers.VisualBasic.Compilation._Closure$__11._Lambda$__59()
в System.Lazy`1.CreateValue()
в System.Lazy`1.LazyInitValue()
в System.Lazy`1.get_Value()
в Roslyn.Compilers.VisualBasic.DeclarationTable.GetLatestRootDeclarationIfAny(Boolean includeEmbedded)
в Roslyn.Compilers.VisualBasic.DeclarationTable.GetMergedReferenceDirectives()
в System.Lazy`1.CreateValue()
в System.Lazy`1.LazyInitValue()
в System.Lazy`1.get_Value()
в Roslyn.Compilers.VisualBasic.DeclarationTable.get_ReferenceDirectives()
в Roslyn.Compilers.VisualBasic.Compilation.get_ReferenceDirectives()
в Roslyn.Compilers.CommonAssemblyManager`3.GetCompilationReferences(TCompilation compilation, DiagnosticBag diagnostics, List`1 references, IDictionary`2& boundReferenceDirectives, List`1& referenceDirectiveLocations)
в Roslyn.Compilers.CommonAssemblyManager`3.ResolveMetadataReferences(TCompilation compilation, List`1 references, IDictionary`2& boundReferenceDirectiveMap, ReadOnlyArray`1& boundReferenceDirectives, List`1 assemblies, List`1 modules, DiagnosticBag diagnostics)
в Roslyn.Compilers.VisualBasic.Compilation.AssemblyManager.CreateSourceAssemblyForCompilation(Compilation compilation, Dictionary`2& referencedAssembliesMap, Dictionary`2& referencedModulesMap, IDictionary`2& boundReferenceDirectiveMap, ReadOnlyArray`1& boundReferenceDirectives, SourceAssemblySymbol& assemblySymbol, DiagnosticBag& diagnostics)
в Roslyn.Compilers.VisualBasic.Compilation.AssemblyManager.CreateSourceAssemblyForCompilation(Compilation compilation)
в Roslyn.Compilers.VisualBasic.Compilation.EnsureSourceAssemblyCreated()
в Roslyn.Compilers.VisualBasic.Compilation.get_SourceAssembly()
в Roslyn.Compilers.VisualBasic.Compilation.get_Assembly()
в Roslyn.Compilers.VisualBasic.Compilation.get_SourceModule()
в Roslyn.Compilers.VisualBasic.Compilation.GetSemanticModel(SyntaxTree syntaxTree)