16

I just upgraded Visual Studio 11 Beta to the new Visual Studio 2012 RC and have problems referencing TPL Dataflow.

First, I tried to reference Dataflow as I did previously, by adding a reference from the framework. But when I try to do that, I get an error box:

A reference to 'System.Threading.Tasks.Dataflow' could not be added.

and then the whole Visual Studio freezes.

After reading MEF and TPL Dataflow NuGet Packages for .NET Framework 4.5 RC, I assumed the version of Dataflow that showed in the references list was some kind of artifact of the previous installation. So, I tried using Dataflow from NuGet, which seemed to work, until I actually tried to compile my code, because I got an error:

The type 'System.Threading.Tasks.Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

This is confusing, because Task is in mscorlib, no other references should be necessary. But there is a reference assembly called System.Threading.Tasks in the references list, so I tried to add that. Unfortunately, a familiar error showed:

A reference to 'System.Threading.Tasks' could not be added.

and then Visual Studio froze again.

Am I doing something wrong? How can I use TPL Dataflow with VS 2012 RC?

Oleg
  • 220,925
  • 34
  • 403
  • 798
svick
  • 236,525
  • 50
  • 385
  • 514
  • Is this a new project or an existing one? – James Manning Jun 03 '12 at 18:16
  • The problem happens when creating a new project. Opening a project created with VS11 Beta that already used TPL Dataflow works fine. – svick Jun 03 '12 at 18:18
  • [I have posted this bug to Connect.](https://connect.microsoft.com/VisualStudio/feedback/details/746558/problems-with-references-to-tpl-dataflow-and-tpl) – svick Jun 05 '12 at 10:15
  • @svick: You bug report can't be accessed by other people. – Oleg Jun 05 '12 at 16:41
  • @Oleg You're right, sorry, I didn't notice that. Should be fixed now. – svick Jun 05 '12 at 17:12
  • Interesting: repairing the installation removed STTD and STT from the references list, but the NuGet TPL Dataflow still requires it. – svick Jun 05 '12 at 18:47

2 Answers2

25

Try to "Add Reference" the System.Threading.Tasks.dll explicitly from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5. Alternatively you can use C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades directory.

UPDATED: I examined the problem more after reading of the answer about removing the reference to System.Runtime and I can add the following: The reference to System.Runtime will be added because of the error in the currect version of NuGet package Microsoft.Tpl.Dataflow.4.5.1-rc. If one add the reference to the same System.Threading.Tasks.Dataflow.dll directly in Visual Studio no System.Runtime reference will be added and no problem exist.

Using NuGet Package Explorer one can download the original Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg from the "NuGet official package source". At the end of the Package Matadata one will see

enter image description here

One can modify the metadata (press Ctrl-K) and remove the reference:

enter image description here

After that one can save the modified file Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg in some directory. After adding new location (the local directory) in the list of NuGet sources (see here or here) one will be able to add new package from the local source (don't forget to choose to display all packages inclusive pre-release see the picture below):

enter image description here

The modified Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg will not add System.Runtime and the project will be compiled without errors.

So the bug exist not in Visual Studio 2012 RC and even not in Microsoft.Tpl.Dataflow.dll. The bug is just in the metadata of the pre-release version of Microsoft.Tpl.Dataflow NuGet package available currently on "NuGet official package source".

You can post the bug report to the autors so that the package will be fixed.

UPDATED 2: Even if my answer are already marked as solved and the bounty awarded the problem still not go from my head. In reality I see two opened problems:

  1. Why the existence of unused assembly System.Runtime can produce the error during the builging of the project.
  2. I see some general problems in the way how Uninstall or Update of NuGet packages works (see details later).

Let us we accept just the fact that the first problem exist independent from the reason. The second problem make me restlessness. I see the real problem here. Everybody can make the following experiment to understand me better:

  1. Create a new empty console application in Visual Studio 2012 RC.
  2. Verify that the project has no reference to System.Runtime.
  3. Open "Package Manager Console" from "Tools" / "Library Package Manager".
  4. Execute the command "Install-Package Microsoft.Tpl.Dataflow -Pre" in the "Package Manager Console".
  5. Verify that both System.Runtime and System.Threading.Tasks.Dataflow are included in the list of References of the project.
  6. Execute the command "Uninstall-Package Microsoft.Tpl.Dataflow" in the "Package Manager Console".
  7. Verify that System.Threading.Tasks.Dataflow are removed from the list of References of the project, but System.Runtime is still in the list of references.

I made one more experiment and I changed the version of modified Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg, where I removed the reference to System.Runtime, from 4.5.1-rc to 4.5.1-rc1 and saved it locally (it will be saved under Microsoft.Tpl.Dataflow.4.5.1-rc1.nupkg). After that I could see "new" version in the list of Updates to my project:

enter image description here

If I install the Update the reference to System.Runtime will be also not removed.

So the current implementation of "Update" and "Uninstall" of NuGet has the bug or general design problem. If we added a package to our project and make some updates of the project we will get references of all dependent assemblies of all old versions. The old references, added by NuGet from old versions of the package, will be not removed during Uninstall or Update. First of all it's not good itself to have garbage in the project references, but because of existence the first problem (error during compilation if the reference to unreferenced System.Runtime exist) the problem will be even more serious.

So if nothing will be changed in NuGet the update to the next version of Microsoft.Tpl.Dataflow will not solve the problem for the users who installed Microsoft.Tpl.Dataflow in version 4.5.1 (or probably early version). All users will have to remove the reference to System.Runtime manually. I think that it's real NuGet problem which have to be solved by NuGet developers. I will post the description of the problem to http://nuget.org/ later.

The bug report which I posted to NuGet can be found here (sorry for not perfect formatting of the text).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks, that seems to work (I used the second one). Any idea why this happens? – svick Jun 05 '12 at 17:18
  • @svick: I don't examined the problem in details. Without the reference the new version of `System.Threading.Tasks.Dataflow` tried to use wrong version of `System.Threading.Tasks.dll`. I don't used TPL Dataflow before. I just copied the demo code from [the page](http://msdn.microsoft.com/en-us/library/hh194684(v=vs.110).aspx) and get the error which you described and the error in the line `workerBlock.Completion.Wait();`: Wait method is not exist. It was clear that Microsoft changed some classes and I used wrong assembly. So one needed only to find the correct one. – Oleg Jun 05 '12 at 17:32
  • @svick: By the way I found at the end of [the blog](http://blogs.microsoft.co.il/blogs/oshvartz/) the tip to add the same reference as I descried in my answer. So it seems that you are not the first person who has the problem. – Oleg Jun 05 '12 at 19:07
  • Thanks for the details. I don't think notifying the authors of the NuGet package is necessary, since Alok Shriram, who is listed among the owners of that package, is the one who responded on social.msdn with the System.Runtime fix and said that it will be fixed in the next release (not sure whether he meant next release of the package or of Visual Studio). – svick Jun 08 '12 at 00:09
  • @svick: You are welcome! I understood [the answer of Alok Shriram](http://social.msdn.microsoft.com/Forums/en-US/tpldataflow/thread/af4dc0db-046c-4728-bfe0-60ceb93f7b9f#9e20d2ec-3b96-444d-98d7-028c4c2b74b7) more as the error exist in Visual Studio 2012 RC, because he emphasized that the problem exist especially in RC. Probably I misunderstood the answer, but it was not so clear. In any way fixing one element of small XML metadata file and publishing on the NuGet online is really easy. I don't understand why one should wait for some "next release". – Oleg Jun 08 '12 at 05:25
  • @svick: I write one more "UPDATE" to my answer where I described one more important problem which I still see in NuGet Update/Uninstall. – Oleg Jun 08 '12 at 08:26
  • [Turns out, we didn't have to wait long for that release.](http://social.msdn.microsoft.com/Forums/en-US/tpldataflow/thread/af4dc0db-046c-4728-bfe0-60ceb93f7b9f#39b3b125-9bd3-4810-8f09-34ff90a72277) I can confirm that the updated NuGet package works correctly (it doesn't add reference to System.Runtime). – svick Jun 08 '12 at 21:40
  • @svick: It's very good news. The new 4.5.4-rc version has no referenced to unused assembly `System.Runtime`. I am sure that it will help other users of the package. About my [bug report](http://nuget.codeplex.com/workitem/2301) to NuGet developers I don't found understanding of the problem. Many year ago I spend many my time to software deployment. I see the problem which I posted to NuGet as serious design problem, but I don't wont to sent my time now with long discussion in comments to the bug report. I reported. One see no problem. OK. In any way your question was interesting for me. – Oleg Jun 09 '12 at 22:42
  • The step "Add Reference to the System.Threading.Tasks.dll" helped me to solve the same issue in a similar issue: .Net 4.6 Roslyn compiler wasn't recognizing a Task<> return inside a Portable Class Library (PCL) referenced in my project. – digiogo Oct 18 '15 at 19:08
  • @digiogo: You are welcome! I'm glad to know that the old answer is still helpful for some cases. – Oleg Oct 18 '15 at 19:26
2

According to Alok Shriram from MS, the solution is to remove the reference to System.Runtime, and that this will be fixed in the next release.

I can confirm that removing the reference actually fixes the issue.

svick
  • 236,525
  • 50
  • 385
  • 514
  • Removing of the reference to `System.Runtime.dll` from the project is better as to add new reference `System.Threading.Tasks.dll`. From the other side it don't really clear *why* the conflict exist. I examined the Manifest of `System.Runtime.dll` with respect of "IL Disassembler" (ildasm.exe) and could not see any conflicts. So for me both ways are like: "Do this and the problem will be solved". So I can repeat the same question which you asked me first: "Any idea why this happens?" – Oleg Jun 07 '12 at 20:52
  • Yeah, I'd like to know too. SR doesn't contain any AssemblyRef to STT, so I have no idea why does removing it help. – svick Jun 07 '12 at 21:16
  • Moreover, the reference to `System.Runtime` was added **by the executing of `Install-Package Microsoft.Tpl.Dataflow -Pre`**, but fhe file `system.threading.tasks.dataflow.xml` don't contain any `System.Runtime` text. If we would have some assembly loading problems we could use [Fuslogvw.exe](http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx) for tracing, but we have *compiler error*. By the way I used [ReSharper](http://confluence.jetbrains.net/display/ReSharper/ReSharper+7+EAP) which help to removed unused references, but it don't removed `System.Runtime` like other references. – Oleg Jun 07 '12 at 21:35
  • By the way if one remove *both* references and then add manually `.\packages\Microsoft.Tpl.Dataflow.4.5.1-rc\lib\net45\System.Threading.Tasks.Dataflow.dll` the second dll (`System.Runtime.dll`) will be not added. So I suppose that the reason can be more in the NuGet package. I examined it with respect of [NuGet Package Explorer](http://nuget.codeplex.com/releases/view/59864), but one can't see directly any reference to `System.Runtime.dll` (at least in GUI of NuGet Package Explorer). So the problem is still not full clear for me. – Oleg Jun 07 '12 at 21:39
  • Oh I was not carefully enough. The NuGet Package Explorer do shows that `Microsoft.Tpl.Dataflow` require `System.Runtime.dll`. In the Package metadata under "Framework Assembly References" one see "System.Runtime". So at least the part of the origin of the problem: `Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg` contains the reference to `System.Runtime.dll` which is wrong. – Oleg Jun 07 '12 at 22:14
  • We've posted version 4.5.4-rc of the NuGet package to fix this issue. – Nicholas Blumhardt Jun 20 '12 at 18:53