Using C ++ / CLI Action <..., ...> and Func <...> is not supported?

it doesn't seem like there is support for Action and Func delegates in the System namespace in C ++ / CLI. At least not for a few general arguments, such as:

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

Both results lead to errors, for example:

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

Only one argument Action:

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

Does anyone know why or what is missing to make this work. I am using Visual Studio 2008, and the project has a target structure of 3.5.

+4
source share
2 answers

The location of the Action and Func types differs depending on the version of the frame used.

Within 3.5, all Func definitions (generic or non-generic) are in System.Core.dll. This is also true for versions of Action with 2 or more common parameters. Action and Action<T1,T2> are in mscorlib though.

In framework 4.0, all Func and Action definitions have moved to mscorlib. System.Core has built-in type forwarders, which now reference mscorlib.

Silverlight 4.0 is closer to solution 3.5.

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

+8
source

In mscorlib -

The following values ​​are defined:
 Action Action<T> 

But the following are defined in System.Core.

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

You are probably missing a link to this assembly.

+8
source

Source: https://habr.com/ru/post/1300204/


All Articles