Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++/CLI use of Action<...,...> and Func<...> unsupported?

it does not look like there is support for the Action and Func delegates in the System namespace in C++/CLI. At least not for multiple generic arguments such as:

System::Action<int, int>^ action = nullptr;
System::Func<int, int>^ func = nullptr;

Both result in errors such as:

error C2977: 'System::Action' : too many generic arguments  
error C2955: 'System::Action' : use of class generic requires generic argument list 

Only single argument Action works:

System::Action<int>^ action = nullptr;

Anyone, knows why or what is missing to make this work. I am using Visual Studio 2008 and the project has target framework 3.5.

like image 653
nietras Avatar asked Feb 03 '10 17:02

nietras


2 Answers

The location of the Action and Func types is different depending on the framework version you are using.

In the 3.5 framework all definitions of Func (generic or not generic) reside in System.Core.dll. This is also true for versions of Action with 2 or more generic parameters. Action and Action<T1,T2> are in mscorlib though.

In the 4.0 framework all of the definitions of Func and Action moved to mscorlib. There are type forwarders inserted into System.Core which point back to mscorlib now.

Silverlight 4.0 is closer to the 3.5 framework solution.

Make sure you have a reference to the appropriate DLL for your solution.

like image 148
JaredPar Avatar answered Oct 23 '22 15:10

JaredPar


The following are defined in mscorlib -

Action
Action<T>

But the following are defined in System.Core.

Action<T1, T2>
Func<T1, T2>

You're probably missing a reference to that assembly.

like image 32
Brandon Cuff Avatar answered Oct 23 '22 15:10

Brandon Cuff