locked
Error while using delegate with different no. of parameters in Visual Studio 2012

    Question

  • Can anyone help me with the following compiler error in VS2012 RC

    #pragma once

    #include <collection.h>

    #using <mscorlib.dll>

    namespace test1

    {

    public delegate void test (Platform::String^ s, int _r_s, int _t_z_,System::IO::File^ _f);

    public ref class Class1 sealed

    {

    public:

    event test^ t;

    void receive(void);

    void cancel(void) ;

    };

    }

    compiles successfully but when I increase a parameter :

     

    #pragma once

    #include <collection.h>

    #using <mscorlib.dll>

    namespace test1

    {

    public delegate void test (Platform::String^ s, int _r_s, int _t_z_,System::IO::File^ _f,int a);

    public ref class Class1 sealed

    {

    public:

    event test^ t;

    void receive(void);

    void cancel(void) ;

    };

    }

     

     

     

    I am getting the following error:

     

    1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\vccorlib.h(2300): error C3481: '____arg4': lambda capture variable not found

    1> d:\test\app2\test1\class1.h(14) : see reference to function template instantiation 'void Platform::EventSource::InvokeVoid<test1::test,Platform::String^,int,int,System::IO::File^,int>(Platform::Details::EventLock *,__TArg0,__TArg1,__TArg2,__TArg3,__TArg4)' being compiled

    1> with

    1> [

    1> __TArg0=Platform::String ^,

    1> __TArg1=int,

    1> __TArg2=int,

    1> __TArg3=System::IO::File ^,

    1> __TArg4=int

    1> ]

    1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\vccorlib.h(2301): error C3493: '__arg4' cannot be implicitly captured because no default capture mode has been specified

     

     

    The same error occurs for 6 parameters.

    Again when I use 7 parameters with the delegate :

     

     

    #pragma once

    #include <collection.h>

    #using <mscorlib.dll>

    namespace test1

    {

    public delegate void test (Platform::String^ s, int _r_s, int _t_z_,System::IO::File^ _f,int a,int b , int c);

    public ref class Class1 sealed

    {

    public:

    event test^ t;

    void receive(void);

    void cancel(void) ;

    };

    }

    The code compiles successfully.

     

     

    Is it a bug from VS2012 t? It would be great if someone can suggest me a way around to fix this issue.

    Tuesday, July 31, 2012 4:26 AM

Answers

  • The code is importing CLR types together with WinRT types in the same file. This is not allowed. If I replace System::IO::File^ with Windows::Storage::StorageFile^ in the signature and remove the #using <mscorlib.dll> I don't see any errors compiling regardless of the number of parameters.

    With the RTM release of Visual Studio, we made it a lot more explicit that this scenario is not supported:

    fatal error C1114: 'c:\windows\microsoft.net\framework\v4.0.30319\mscorlib.dll' : WinRT does not support #using of a managed assembly

    Thanks,
    Marian Luparu
    Visual C++

    Friday, August 03, 2012 12:10 AM

All replies

  • Hi Darkblue12,

    Thank you for your post.

    Based on this case relate to Metro style apps with C++, I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.

    Best regards,

    Ego [MSFT]
    MSDN Community Support | Feedback to us


    Wednesday, August 01, 2012 2:37 AM
  • Hello,

     

    Thanks for your feedback, I will involve more experts to investigate it.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 02, 2012 9:16 AM
  • The code is importing CLR types together with WinRT types in the same file. This is not allowed. If I replace System::IO::File^ with Windows::Storage::StorageFile^ in the signature and remove the #using <mscorlib.dll> I don't see any errors compiling regardless of the number of parameters.

    With the RTM release of Visual Studio, we made it a lot more explicit that this scenario is not supported:

    fatal error C1114: 'c:\windows\microsoft.net\framework\v4.0.30319\mscorlib.dll' : WinRT does not support #using of a managed assembly

    Thanks,
    Marian Luparu
    Visual C++

    Friday, August 03, 2012 12:10 AM