'Expected Global Line.' exception while loading solution using Roslyn

拟墨画扇 提交于 2019-12-11 10:46:27

问题


I'm learning Roslyn and trying it out for the first time. I've written a small code snippet to load a solution and get a reference to a workspace.

IWorkspace workspace = Workspace.LoadSolution(solutionPath);

foreach (IProject project in workspace.CurrentSolution.Projects)
{
    CommonCompilation objCompilation = project.GetCompilation();
}
return workspace;

But I'm getting an exception in the first line. The exception details are given below.

Message : Expected Global Line.

stack trace :
at Roslyn.Services.Host.SolutionFile.ParseGlobal(TextReader reader)
at Roslyn.Services.Host.SolutionFile.Parse(TextReader reader)
at Roslyn.Services.Host.LoadedWorkspace.LoadSolution(SolutionId solutionId, String filePath)
at Roslyn.Services.Host.LoadedWorkspace.OpenSolution(String fileName)
at Roslyn.Services.Host.LoadedWorkspace.LoadSolution(String solutionFileName, String configuration, String platform, Boolean enableFileTracking)
at Roslyn.Services.Workspace.LoadSolution(String solutionFileName, String configuration, String platform, Boolean enableFileTracking)
at Ros2.Program.GetWorkspace(String solutionPath) in c:\users\amnatu\documents\visual studio 2015\Projects\Ros2\Ros2\Program.cs:line 30

I referred to this link which shows the same issue that I faced. However, the solution of removing the space between EndProject and Global isn't really applicable in my case as my solution file doesn't have any space between them.

Am I missing anything here?
Any suggestions on how to resolve this issue?


回答1:


Apologies for the delayed response. The comment by @JoshVarty helped me understand the issue.

I was indeed using the out dated version and had to use the latest Microsoft.CodeAnalysis library. After I made these changes and updated all classes accordingly, everything worked perfectly.

Thanks JoshVarty.!



来源:https://stackoverflow.com/questions/31781140/expected-global-line-exception-while-loading-solution-using-roslyn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!