Roslyn .Net core Compilation Fails

Sundar Doss 1 Reputation point
2022-11-18T17:27:29.37+00:00

I am using Roslyn 4.4.0 , when i try below code i am getting compilation error, below are some sample error

error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
error CS0246: The type or namespace name 'IHttpActionResult' could not be found (are you missing a using directive or an assembly reference?)

all these packages are available

  • Restored packages
    var solution = await workspace.OpenSolutionAsync(solutionInfo.LocalSolutionPath);
    var projectCompilation = await solution.GetProject(project.Id).GetCompilationAsync();

the same works fine when try below code

var nugetworkspace = MSBuildWorkspace.Create();
var solution = await nugetworkspace .OpenSolutionAsync(solutionInfo.LocalSolutionPath);
restore package

then load solution again and compile, compiles without error
var workspace = MSBuildWorkspace.Create();
var solution = await workspace.OpenSolutionAsync(solutionInfo.LocalSolutionPath);
var projectCompilation = await solution.GetProject(project.Id).GetCompilationAsync();

Any idea why?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,947 questions
{count} votes