MSBuild doesn't find async required references
Asked Answered
D

2

6

We have Visual Studio 2010 SP1 and Async CTP (SP1 refresh) installed.

A solution with projects that use async/await keywords builds OK when build from VS IDE. Also when built with devenv /build "Debug" solution.sln everything is OK.

However msbuild @commands.rsp solution.sln reports:

File.xaml.cs(123): error CS1993: Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?

commands.rsp looks like this:

/nologo
/p:Configuration=Debug
/m:3
/fileLogger

Any clues?

Deadlock answered 7/3, 2012 at 11:5 Comment(1)
Can you post your commands.rsp?Teriteria
V
4

Please, refer to the discussion here: http://social.msdn.microsoft.com/Forums/uk-UA/async/thread/3d491cb0-a19f-4faf-80a6-5fd05e4e06db

There are 2 points to be clarified in order to understand better your problem:

  • Environment: did you install VS11 side-by-side with VS 2010+Async CTP?
  • Your project: do you have XAML with user controls and "clr-namespace" in your project?

I will cite the preliminary conclusion by SERware from the discussion on the MS forum:

I think it has to do with the order in which the XAML projects compile assemblies when referring to classes of the library itself. In this case, the XAML Loader try to compile this classes before having reference to the Async CTP library. So, the keyword "async" is not recognized.

Personally I am going to see whether it is possible to split the assembly in order to resolve the order of the compilation of the dependencies in XAML

Added after further investigation: As I have found out, the explanation is even more disappointing: the .NET 4.5 (Beta) replaces the .NET 4.0. Besides, the signatures of the async/wait related types have been internally changed. Therefore there is no way so far to use simultaneously VS 2010+AsyncATP and VS11 Beta. – Yuri S. 2 mins ago

Vowelize answered 8/3, 2012 at 15:22 Comment(2)
First point, Yes I do have VS11 installed. However my workmate doesn't, and he got same errors. On the second point, all async/await calls in our case are in ViewModel, so they don't have a counterpart xaml (my error example there is misleading because I didn't have ours in scrollback anyways and that was the one that had same error description and code)Deadlock
As I have found out, the explanation is more disappointing even more: the .NET 4.5 (Beta) replaces the .NET 4.0 Besides, the signatures of the async/wait related types have been internally changed. Therefore there is no way so far to use simultaneously VS 2010+AsyncATP and VS2011 Beta.Vowelize
E
0

I was hit by this myself and for various reasons I can't upgrade the projects to .NET 4.5 so I had to develop a workaround.

Since this is only a problem for XAML projects that has a xmlns declaration pointing to itself I'm able to use async on all the other projects that are referenced. This means my architecture is still utilizing async/await and is prepared for the move to .NET 4.5 later.

But in the affected XAML projects, I just manually implement (poorly) the await things otherwise done by the compiler.

So code that was this clean before:

try
{    
    var foo = GetFoo();
    foo.DoStuff();
    var data = await foo.GetDataAsync();
    bar.WorkOnData(data);
}
catch (Exception ex)
{
    // Logging, throw up a popup, whatever...
    HandleError("Failed to get data", ex);
}

Now becomes this:

var foo = GetFoo();
foo.DoStuff();
var getDataTask = foo.GetDataAsync();
getDataTask.ContinueWith(t =>
    {
        if (t.IsFaulted)
        {
            // Logging, throw up a popup, whatever...
            HandleError("Failed to get data", t.Exception);
            return;
        }
        if (t.Status == TaskStatus.RanToCompletion)
        {
            bar.WorkOnData(t.Result);
        }
     });

Not ideal of course, and this is the exact thing that async/await was created to solve. But it does work as a short-term workaround at least for simple uses of await.

Enervated answered 19/9, 2012 at 8:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.