dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.17k stars 1.34k forks source link

Could not load file or assembly 'System.Threading.Tasks.Dataflow' on Mono #2423

Open abhijitparkhi1983 opened 6 years ago

abhijitparkhi1983 commented 6 years ago

Hi,

I am trying to use Roslyn's workspace.OpenProjectAsync api to load and open a Microsoft.CodeAnalysis.Project object using following code:

var workspace = MSBuildWorkspace.Create();
workspace.WorkspaceFailed += WorkSpaceFailed;
Project currentProject = workspace.OpenProjectAsync(projectPath).Result;
Console.WriteLine(currentProject.Documents.Count());

When I run the above code on Windows 7 machine, the currentProject.Documents.Count() code gives a valid count of Documents present in the Project. The .NET framework used is .NET 4.6.1

But when we run the same code on Ubuntu (Version 16.04) using Mono (Version 5.0.1), the currentProject.Documents.Count() code returns 0 always and the WorkSpaceFailed event shows following exception:

Could not load type of field 'Microsoft.Build.BackEnd.Logging.LoggingService:_loggingQueue' (20) due to: Could not load file or assembly 'System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. assembly:System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type: member:

AndyGerlicher commented 6 years ago

@jaredpar is the Roslyn Project Workspace API expected to work on Mono?

jaredpar commented 6 years ago

CC @DustinCampbell

DustinCampbell commented 6 years ago

In OmniSharp, we ran into the same and added a specific package reference to System.Tasks.Threading.Dataflow, 4.6.0

abhijitparkhi1983 commented 6 years ago

Hello @jaredpar and @DustinCampbell,

Any Idea how do we add this package reference for Mono? I am very new to using mono and not sure how do we add such references. Inputs from you would be of a great help.

AArnott commented 6 years ago

This isn't a Mono-specific bug. I just hit it on Windows. The problem seems to be that the Microsoft.Build nuget package only expresses System.Threading.Tasks.Dataflow as a package dependency for .NETStandard1.5, omitting it from net46. But net46 does not ship this assembly, so you can't assume it's in the GAC. It must be a package dependency for both target frameworks.

I guess it's showing up now for me because I'm on a machine that doesn't have VS 2015 installed (which GAC'd the dll).

Ben-CA commented 4 years ago

Have the same error on VS2019 on Windows 7.

Fergo commented 4 years ago

Have the same error on VS2019 on Windows 7.

Just add the System.Threading.Tasks.Dataflow from the NuGet package manager to the Lang.Php.Compiler project and rebuild the solution.

Uraharadono commented 1 year ago

In my case, I have .Net Framework 4.6.2 application that was throwing this error. To fix it I had to manually install System.Threading.Tasks.Dataflownugget package. Specifically I installed "System.Threading.Tasks.Dataflow": "7.0.0",