Question

The problem I am currently encountering is really weird. I try to use a Managed C++ class from a C# project but the compiler cannot find the type.

Take a look at this screenshot: Problem Screenshot

The Managed C++ project (NGervill.Gervill.Native) is referenced and according to the Object Browser it contains all required namespaces and types. In my source code I've added the using and used the class but still I get a compile error.

Now the strangest part: The other types within the Managed C++ project can be referenced. In another C# class I access the methods of the PortMixerProviderNative class. That means target platform and .net framework version are correct (.net 4.5 - x86 build).

Is Visual Studio somehow caching an old version of the Managed C++ DLL or what else can cause such a problem?

Was it helpful?

Solution 2

I finally found the solution of this problem: For some reason the cpp file implementing the PortMixerNative class was not included in the project. After adding the PortMixerNative.cpp to the project again I finally could see that there were syntax errors in this file. After fixing the errors and recompiling the .Native project I could successfully reference the class.

The strange thing is that the .Native project successfully compiled even with methods without implementations. If anybody encounters this problem too, check if all methods of the class you try to use have an implementation.

OTHER TIPS

PortMixerNative is a native C++ class, not a managed class. Native classes can be exposed in the assembly metadata in some cases, usually because they are the type of a private field in a managed class wrapper, but they are not usable in any way from a C# program. Only public ref class declarations in the C++/CLI project are usable.

It isn't clear what wrapper class you are supposed to use. Not PortMixerNative. Check the vendor's manual and/or code samples or contact them if you need more help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top