Compiler error awaiting IObservable when compiled with csc.exe
-
Tuesday, September 18, 2012 8:11 AM
The following program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main (string [] args)
{
Foo ().Wait();
}
static async Task Foo()
{
string hello = await Observable.Return ("Hello, world");
Console.WriteLine (hello);
}
}
}
compiles and runs perfectly in Visual Studio 2012. But if you try and compile the same program via the CSharpCodeProvider or the command-line compiler:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc /r:System.Reactive.Interfaces.dll /r:System.Reactive.Core.dll /r:System.Reactive.Linq.dll /r:System.Reactive.PlatformServices.dll /r:C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.dll Program.cs
the compiler generates the following error:
Program.cs(18,19): error CS4027: 'System.Reactive.Subjects.AsyncSubject<string>' does not implement 'System.Runtime.CompilerServices.INotifyCompletion'
I've tried this on both Windows 7 and Windows 8 machines. Obviously, Framework 4.5 is installed, and the compiler has been successfully patched for C# 5, because it recognizes the async and await keywords. The Rx assemblies are from Rx-Main, v2.0.20823. Opening System.Reactive.Linq.dll in Reflector shows that the AsyncSubject<> type indeed implements System.Runtime.CompilerServices.INotifyCompletion.
What could cause this, and is there a workaround? FWIW, it didn't happen in Framework 4.0 with the async CTP.
Joe
P.S. You can reproduce this by awaiting an observable in LINQPad (LINQPad relies on CSharpCodeProvider, which relies on csc.exe).
- Edited by Joe AlbahariMVP Tuesday, September 18, 2012 8:23 AM
All Replies
-
Tuesday, September 18, 2012 10:34 AM
For anyone else running into this problem, adding a reference to System.Threading.Tasks.dll fixes it.
System.Threading.Tasks.dll is an undocumented assembly that's referenced by System.Reactive.Linq.dll. It contains just type forwarding attributes (and no types). If you don't explicitly reference this assembly, along with System.Runtime.dll, the type forwarding goodness doesn't occur and you get the unhelpful compiler error.
What I don't understand is why a project created in Visual Studio doesn't require these references. As I understand, VS uses msbuild rather than csc.exe, so presumably there's some automagic going on there.
- Proposed As Answer by LeeCampbell Tuesday, September 18, 2012 3:33 PM
-
Wednesday, October 03, 2012 8:25 AMOwner
This assembly reference is a result of using Portable Library for the main build of Rx. When using the "new profile" (i.e. .NET 4.5 + .NET for Windows Store apps), references are made to the refactored set of framework assemblies (including things like System.Collections.dll etc.). To see how such a library compiles, have a look at the csc.exe string found in the output of msbuild /flp:verbosity=diag MyPlib.csproj. You'll find *all* of the refactored .NET Framework assemblies get passed in /r flags. You may want to do the same for a regular Console app to see what's referenced nowadays when going through MSBuild (for one thing, I know the nostdlib flag is passed by default now, explicitly passing a reference to the desired mscorlib.dll all the time).
using (Microsoft.Sql.Cloud.DataProgrammability.Rx) { Signature.Emit("Bart De Smet"); }
-
Saturday, November 17, 2012 10:40 PM
I'm building a console application in VS2010 and added the RX lib via NuGet and I have the error in question.
The application I am working on is a new version of an existing application and the original has the very same RX usage doing the same job but that version works. NuGet has given me the latest version which doesn't work.??[A race to the bottom]
The VipX

