I'm trying to load an existing C# project and analyze one of its source files using Roslyn. However, when compiling the source file, I get compilation errors which make no sense and are not present when compiling with Visual Studio. (the code also runs fine)
Can anyone help me to diagnose this problem?
Parts of the code used to compile the file:
var oriSln = workspace.OpenSolutionAsync(@"absolutepath.sln").Result;
var oriProject = oriSln.Projects.First(p => p.Name == "projectname");
var doc = oriProject.GetDocument(docId);
var model = doc.GetSemanticModelAsync().Result;
var diag = model.GetDiagnostics(); // has strange errors
The errors:
thefile.cs(36,68): error CS0518: Predefined type 'System.Void' is not defined or imported
thefile.cs(40,74): error CS0518: Predefined type 'System.Void' is not defined or imported
thefile.cs(40,50): error CS1503: Argument 1: cannot convert from 'float' to 'int'
thefile.cs(41,50): error CS1503: Argument 1: cannot convert from 'float' to 'int'
thefile.cs(51,50): error CS1503: Argument 2: cannot convert from 'float' to 'int'
thefile.cs(58,58): error CS1503: Argument 2: cannot convert from 'float' to 'int'
thefile.cs(130,40): error CS0518: Predefined type 'System.ValueType' is not defined or imported
thefile.cs(168,55): error CS0246: The type or namespace name 'Vector3' could not be found (are you missing a using directive or an assembly reference?)
thefile.cs(158,38): warning CS0168: The variable 'ex' is declared but never used
thefile.cs(7,1): hidden CS8019: Unnecessary using directive.
thefile.cs(6,1): hidden CS8019: Unnecessary using directive.
The solution consists of about 30 projects, the target project references some of these, and also some third parties, one of which contains the Vector3
.