locked
async method compiler error on XAML projects that reference own assembly RRS feed

  • Question

  • Yesterday I reported a problem in the parallel extensions to the NET. Frameworkd forum.

    async await problem installing side by side VS 11 Beta with VS 2010

    I've been eliminating elements of my project and now I can reproduce the problem. Now I think it is a problem of the Async Ctp and XAML projects in general. That is why I am now reporting in this forum.

    First I uninstalled VS 11 Beta. Then VS 2010 had a problem at startup, so I had to repair its installation  (but that is another problem that I have no time to investigate).

    After succesful repairing VS 2010. The compiler reported another different error in asynchronous methods in some of my XAML projects.

    I was removing elements and now I know how to reproduce the error.

    Is quite simple:

    1. Create a default WPF User Control project

    2. Add a reference to the NET Async Ctp library

    3. Add this lines to the default User Control behind code

    using System.Threading.Tasks;
    
    namespace WpfControlLibrary1
    {
        /// <summary>
        /// Interaction logic for UserControl1.xaml
        /// </summary>
        public partial class UserControl1 : UserControl
        {
    
            public async Task SomethingToDoAsync()
            {
                await TaskEx.Yield();
            }
    
            public UserControl1()
            {
                InitializeComponent();
            }
        }
    }


    4. Build the project: no errors now


    5. Insert the following line in the XAML of your user control

           xmlns:own="clr-namespace:WpfControlLibrary1"

    6. VS reports the error: "expected ; "

    What has happened?

    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.

    I think that the problem is not related to the installation of VS 11 Beta. But when it was installed the error was more explicit:

    "Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?"

    ¿Workarounds? I can imagine several but none like me.

    ¿Any ideas?

    Thanks

    • Edited by SERware Wednesday, March 7, 2012 10:07 AM spelling
    Wednesday, March 7, 2012 9:57 AM

Answers

  • Did you try to re-install Async CTP 3?
    • Marked as answer by SERware Wednesday, March 7, 2012 11:45 PM
    Wednesday, March 7, 2012 11:04 PM

All replies

  • Did you try to re-install Async CTP 3?
    • Marked as answer by SERware Wednesday, March 7, 2012 11:45 PM
    Wednesday, March 7, 2012 11:04 PM
  • Thaaaaaaaaaaanks Yuri!!!

    All is ok after re-installing Async CTP 3.

    I didn't re-install Async CTP 3, because except those methods in projects with XAML, all
    async methods compiled correctly.

    Perhaps the problem comes from side by side installation of VS 11 Beta and VS 2010 SP1 with Async CTP. I don't know.

    It's a pity, but I'll have to install VS 11 Beta out of my development PC for testing.

    Thanks again

    Wednesday, March 7, 2012 11:45 PM
  • I believe you are right in your description of the problem.

    I have 2 WPF/XAML  projects.

    My old simple test WPF/XAML GUI perfectly compiles with Async CTP.

    However the production GUI with user controls and clr-namespace fails like in your case.

    I agree that most probably the order of assembly compilation is indeed the root of the problem.

    The question:

    is it possible to split the GUI assembly with user controls and resolve the problem of the compilation order (at least for the time being)?

     

    Thursday, March 8, 2012 3:12 PM
  • Hi Yuri,

    At last, I believe the source of the problem is the coexistence of VS 11 Beta and VS 2010 with Async CTP applied.

    I believe  all VS 2010 projects can be opened in VS 11 Beta, except if the VS 2010 projects have dependencies on Async CTP. In my case, I tried to open in VS 11 Beta a VS 2010 solution referencing Async CTP library: the error window was filled with weird messages.

    That's normal: VS 11 Beta already incorporates out of the box everything you need for
    async/await (and the new implicit environment can not coexist with the old Async
    CTP library).

    Anyway, I have no time to investigate the problem.

    As to your question, may be a manual build can do the magic, but you will loose intellisense, etcétera, etcétera.

    My solution is: "don't test VS 11 Beta on the same machine if your production code depends on Async CTP."

    There's another solution: "don't use a CTP for your production code...". I agree, but async/await is so cool, that I can´t "await" the oficial 4.5 release :)

    Thanks again

    Thursday, March 8, 2012 6:43 PM
  • One more thing, perhaps the problem with "clr-namespace: namespace" xmlsn clauses, belongs exclusively to VS 11 Beta and its new async/await environment (and not to the mere coexistence with VS 2010 and Asyn CTP). In this case, Microsoft is responsible for fix it, we have already done quite detecting when it occurs.

    And as least for the time being... I'll have the problem testing my code in VS 11 Beta...

    ¿Any ideas?

    Thanks

    Thursday, March 8, 2012 6:58 PM
  • The installation of VS11 installs .NET 4.5 which is an in place update to .NET 4.0. With the changes in the beta, the Async CTP no longer works on systems with .NET 4.5.

    Paulo Morgado

    Thursday, March 8, 2012 8:11 PM
  • Hi Paulo,

    Your information isolates the problem in the .NET 4.5 Beta. I found the problem in VS 2010, but the origin is in the new Framework. Therefore, following my steps, the problem must be reproducible in systems with .NET 4.5 Beta installed.

    Thanks

    Thursday, March 8, 2012 8:32 PM
  • If someone has this problem on an installation side by side of VS 11 Beta and VS 2010 SP1 with Async CTP 3, and wants to return to the previous state, this is a guide to do it:

    1. Uninstall VS 11 Beta, .NET 4.5 and all related products

    2. If after desinstallation there are problems starting VS 2010, repair VS 2010 installation.

    3. Re-install Async CTP 3.

    I believe that it is not necessary to reapply SP1, but it can be done for greater security.

    Hope it helps

    Thursday, March 8, 2012 8:44 PM
  • What I'm saying is that after installing .NET 4.5 you non longer have .NET 4.0 and the CTP was built to work with .NET 4.0.

    Paulo Morgado

    Thursday, March 8, 2012 10:39 PM
  • What I'm saying is that after installing .NET 4.5 you non longer have .NET 4.0 and the CTP was built to work with .NET 4.0.

    Paulo Morgado

    My English is not good, but I think I understand what you've said.

    The rest is my own deduction based on the facts and your information.

    Thanks again.

    Thursday, March 8, 2012 11:35 PM
  • Friday, March 9, 2012 12:33 AM
  • Hi Paulo,

    they didn't fixed the problem in the release version of the Studio 11, did they? :-(

    I can't move to Studio 11 because I'm doing Windows Phone development..

    Thursday, October 18, 2012 9:16 AM
  • I don't think they did or that it will ever be a compatible version for Windows Phone 7.

    I'm changing all my Windows Phone 7 apps from async/await to Rx


    Paulo Morgado

    Thursday, October 18, 2012 11:33 PM
  • I stand corrected: Using async/await without .NET Framework 4.5

    Paulo Morgado

    Wednesday, October 24, 2012 12:29 AM