Native Unit Test (interop of c++ and c#) is not working?

Copper Contributor

How to reproduce:

- Create a new cppUnitTestFramework (native unit test project c++)

- Turn on /clr

- Conformance mode: no (/permissive)

- Debug information Format: none

- Additional #using Directories: pointing to the bin, where the dll is located

- Make sure you make all the above changes, before compiling for the first time

 

Just trying to test interoperability between an EF core context (c#) and a Unit Test in C++ (in other words, a C++ unit test will access the EF context and get data from the DB)... Can't get it to work!

 

There are several issues/warnings/errors I encountered so far:

- C++ Language standard cannot be set above ISO C++ 17 (20 and the latest does not work. In March it is supposed to be released the new version... This means we won't get support again?)

- (Warning) "The initializer for exported data will not be run until managed code is first executed in the host assembly". Does this mean I have to first add and use the C# context.dll before I can compile the C++ Unit Test Project?

-  The moment I activate the /clr and solve all issues[1], the Test Explorer no longer detects the Test Methods. So I can't debug or run them. 

 

What am I doing wrong? I just want to leverage C# code-first database perks, on a C++ Unit Test environment, and in the future in other C++ projects/apps/game-engine!

 

Should I use something else? A template that is not from Microsoft? 

 

[1] - https://learn.microsoft.com/en-us/cpp/build/reference/clr-restrictions?view=msvc-170

1 Reply

Hi @pp,

Thanks for posting your issue here.

However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang