我正在尝试使用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)
答案 0 :(得分:1)
此异常通常表示程序本身已损坏。如果您能够提供故障转储文件,请执行此操作。
另外,请验证您的程序集在某种程度上是否已损坏。我们发布的所有Roslyn二进制文件都经过数字签名,因此请检查您的Roslyn.Compilers.VisualBasic.dll是否具有有效签名。找到DLL,转到Windows资源管理器中的文件属性,数字签名选项卡,然后点击详细信息。确认您看到“签名没问题。”
答案 1 :(得分:0)
事实证明,当我仅在我的网站上使用代码时会抛出异常,然后该网站在VisualStudio Development Server或IIS Express上运行。也通过TestDriven.net和Gallio运行它(可能只是旧版本)。代码运行良好,控制台应用程序或IIS已满。
我仍然认为这是一个错误,因为使用CSharp编译器的类似代码运行得很好。