Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable Class Library with async await & GetType().IsValueType

I need the following calls possible within the same portable class library:

public class Foobar
{
    void Foo()
    {
        var b = GetType().IsValueType; //<-- 2
    }

    async Task<IEnumerable<T>> Bar<T>() 
        where T : class, IBaz, new()
    {
        return await Task.Factory.StartNew(() => new List<T>(new[]   //<-- 1
            {
                new T {Qux = Guid.NewGuid().ToString()}
            }));
    }

    interface IBaz 
    {
        string Qux { get; set; }
    }
}

With the following target frameworks set:

  • .net Framework 4.5
  • Sliverlight 5
  • Windows Phone 8
  • .Net for Windows Store apps

I get this build error:
Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?

I tried to install the bcl but still get the same error. And if I remove the Sliverlight target the async works but then I lose the IsValueType prop from the Type class...

like image 422
jaimie Avatar asked Mar 06 '13 18:03

jaimie


1 Answers

You need to install Microsoft.Bcl.Async.

like image 119
Stephen Cleary Avatar answered Sep 28 '22 03:09

Stephen Cleary