Click here to Skip to main content
14,969,978 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
While i am exporting a C++ code in C# using vector and list and i am getting the below error. In C++ i have used vectors and in C# i have used list to map it properly but somehow its not working.

"Error: additional information: cannot marshal 'return value': generic types cannot be marshaled."

What I have tried:

C++ code
extern __declspec(dllexport) std::vector<db> __cdecl Function()
{
   std::vector<db> result;
--
return result;
}


C# code:

public class Test
    {
        [DllImport("Test.DLL")]
        public static extern List <data> Function();

    }

void importData()
{
List<data> returnValue = Test.Function();
}
Posted
Updated 31-Mar-21 1:30am
v2

1 solution

Correct: Generics can't be marshalled, and a C# Generic is not the same beast as a C++ Template.

See here: Cannot marshal 'return value': Generic types cannot be marshaled.[^] - it shows a way that may help.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900