locked
Intellisence error: a local lambda is not allowed in a member function of a managed class type

    Question

  • Hi, I enountered an error when using the asyncronous pattern: a local lambda is not allowed in a member function of a managed class type.

    Below is the code:

     auto getFileOP = StorageFile::GetFileFromPathAsync(fileName);
     getFileOP->Completed = ref new AsyncOperationCompletedHandler<StorageFile^>
      ([](IAsyncOperation<StorageFile^>^ op)
     {
     });

    This error only occurs in intellisence. I can build the project without any problems. Is this a bug in Visual Studio? It's quite confusing... As I understand, while the syntax of Metro applications look like C++/CLI, it is actually a native application rather than a managed application. So we should not encounter such errors.


    Sining Oh Blue Star
    Monday, September 26, 2011 8:38 AM

Answers

  • Hello,

    The syntax of C++/Cx is similar to C++/CLI but indeed it creates only native WinRT types . In your snippet above, you encountered 2 issues:

    - The Intellisense issue around generics is a known issue for BUILD. Intellisense support for C++/CLI and C++/Cx is still a work in progress but generics will be fully supported.
    - Some error messages (both in Intellisense and compile time) in C++/Cx may incorrectly use the term "managed types". This is also being addressed post BUILD.

    Thanks,
    Marian Luparu
    Visual C++

    • Marked as answer by SALX Tuesday, September 27, 2011 9:48 AM
    Monday, September 26, 2011 5:45 PM

All replies

  • Hello,

    The syntax of C++/Cx is similar to C++/CLI but indeed it creates only native WinRT types . In your snippet above, you encountered 2 issues:

    - The Intellisense issue around generics is a known issue for BUILD. Intellisense support for C++/CLI and C++/Cx is still a work in progress but generics will be fully supported.
    - Some error messages (both in Intellisense and compile time) in C++/Cx may incorrectly use the term "managed types". This is also being addressed post BUILD.

    Thanks,
    Marian Luparu
    Visual C++

    • Marked as answer by SALX Tuesday, September 27, 2011 9:48 AM
    Monday, September 26, 2011 5:45 PM
  • Thanks for the confirmation. This issue is quite annoying. Hope it will be fixed soon.
    Sining Oh Blue Star
    Tuesday, September 27, 2011 9:48 AM
  • The problem is still in Visual Studio 11 beta, and worse, an MSDN page explaining how to build RT Components won't compile due to this error.

    Do you try your sample code, or do you have some version of Visual Studio that doesn't have this problem?

    At LEAST fix the sample code.

    The page with the bad code is

    http://msdn.microsoft.com/en-us/library/windows/apps/hh755833(v=vs.110).aspx

    Thursday, March 8, 2012 9:06 PM
  • +1 on this. Grrrrrrrrrrrrrrrr
    Friday, May 11, 2012 6:09 PM
  • +1. I have been seeing it for a while, but since it still shows up in Win8RP/VS11RC - does it mean that it indeed is not allowed? Will my app not be allowed on the marketplace if I use lambdas in a WinRT type or is it just a bug that has been postponed for a while? The only difference I am seeing is that it mentions WinRT type instead of a managed type now.

    Filip Skakun

    Tuesday, June 5, 2012 5:01 AM
  • Unfortunately the Intellisense fix for this was not fixed prior to us releasing the RC bits, but it is already checked-in and should be in RTM.

    Local lambdas will be allowed in WinRT and it's the primary way to consume Async APIs in C++/CX either directly or via PPL (recommended).

    @SBK11: Are you still seeing any compile-time errors with the code in the Walkthrough?

    Marian

    Monday, June 18, 2012 10:57 PM
  • +1.

    Yes, we all are. The sample code listed does not work -- I downloaded VS Studio 2012 ultimate last week -- same issue.

    Tuesday, September 4, 2012 8:23 AM
  • largole-

    Did you re-copy the code from the current version of the topic? It compiles with no errors or warnings for me on VS2012 Ultimate.

    http://msdn.microsoft.com/en-us/library/windows/apps/hh755833.aspx

    Thursday, September 6, 2012 11:28 PM