1

我正在尝试使用 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)
4

2 回答 2

1

此异常通常表明程序本身已损坏。如果您能够提供故障转储文件,请提供。

此外,请确认您的程序集没有以某种方式损坏。我们提供的所有 Roslyn 二进制文件都经过数字签名,因此请检查您的 Roslyn.Compilers.VisualBasic.dll 是否具有有效签名。找到 DLL,在 Windows 资源管理器中的文件属性下,数字签名选项卡,然后点击详细信息。验证您是否看到“签名正常”。

于 2013-11-14T04:31:17.340 回答
0

事实证明,当我只在我的网站上使用代码时抛出异常,然后网站在 VisualStudio 开发服务器或 IIS Express 上运行。还通过 TestDriven.net 和 Gallio 运行它(可能只是旧版本)。该代码在控制台应用程序或 IIS 完整时运行良好。

我仍然认为这是一个错误,因为使用 CSharp 编译器的类似代码运行得很好。

于 2013-11-21T11:17:56.363 回答