Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with consuming ConfiguredTaskAwaitable from PortableClassLibrary's class under Debugger from MSTest Runner or Console App?

Note: This is only a Debug-time error, but a very weird one.

Problem:

While running with Debugger attached and calling a method, exposed in separate Portable library, returning ConfiguredTaskAwaitable, we get InvalidProgramException.

Reproduce It:

Having 2 projects:

  1. PortableClassLibrary (supporting .Net 4.5; Windows Store; Windows Phone 8) with 1 class:

    public class Weird
    {
        public static ConfiguredTaskAwaitable GetConfiguredTaskAwaitable()
        {
            return new ConfiguredTaskAwaitable();
        }
    }
    
  2. ConsoleApplication with code:

    static void Main(string[] args)
    {
        Weird.GetConfiguredTaskAwaitable();
    }
    

Notes:

  1. replacing ConfiguredTaskAwaitable with ConfiguredTaskAwaitable<T> (a generic version) fixes this strange issue
  2. consuming this method form WP8 or Win8 app under Debugger works fine.

Currently it causes problems cause I cant run my Unit Tests under Debugger. I'm forced to change my "ObjectUnderTest" implementation to return generic ConfiguredTaskAwaitable<T>, which is fine for the real project, but still is only a workaround.

The Question is:

Does anybody know the reason for this error? It's definitely related to Portable Class Library magic.

like image 925
Stas Shusha Avatar asked Dec 05 '12 15:12

Stas Shusha


1 Answers

Are you using Visual Studio Ultimate 2012 with IntelliTrace enabled? This looks like a bug which should be fixed in the latest CTP of Visual Studio 2012, Update 2 and in future releases.

You can confirm this is the problem (and work around it until you get the fix) by going to Tools/Options/IntelliTrace and turning off 'Enable IntelliTrace'.

like image 96
Colin Thomsen Avatar answered Oct 05 '22 00:10

Colin Thomsen