Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in compiling with marshal.h : error C2872: 'IServiceProvider' : ambiguous symbol

Tags:

c++-cli

I am trying to use the marshalling library in my C++/CLI project. When compiled with #include <msclr/marshal.h> I get the error error C2872: 'IServiceProvider' : ambiguous symbol. Most of the resolutions seems to be suggesting moving #include <windows.h> like the one here -> Ambiguous references, but I dont have those includes. All I have is:

using namespace System;
using namespace System::Configuration;
using namespace std;
#include <msclr/marshal.h>

How do I debug this issue ?

like image 800
anivas Avatar asked Oct 22 '10 20:10

anivas


2 Answers

You do, indirectly, marshal.h includes it. It dumps an enormous amount of identifiers in the global namespace. The macros are especially awkward, lots of them match names used in the framework.

Lots of things that marshal.h does can be done by the Marshal class as well. But I can't help you with that, you didn't mention why you want to use it. You can solve this particular mishap by putting the #include directive before the using statements:

#include <msclr/marshal.h>
using namespace System;
using namespace System::Configuration;
like image 72
Hans Passant Avatar answered Oct 16 '22 16:10

Hans Passant


Make sure you only have the:

using namespace System;

in the cpp file of the CLR project and not in the header. Visual studio automatically adds it to the header when creating a CLR class library project. In the cpp itself, the includes must precede the "using namespace".

like image 14
Matan L. Avatar answered Oct 16 '22 15:10

Matan L.