Re: C2872 IServiceProvider ambiguous symbol - migrating C++/MFC App with /clr to Visual Studio 2005



Hi Jeffrey,
Infinite thanks for yet another excellent response.
I followed your instructions and they seem to have solved the compile
problem. So now I've gotten passed the compile stage.
Unfortunately, the link stage has failed with the following errors:

Merging metadata
MainFrm.obj : error LNK2022: metadata operation failed (8013118D) :
Inconsistent layout information in duplicated types (_PROPSHEETPAGEA):
(0x020000f1).
MainFrm.obj : error LNK2022: metadata operation failed (8013118D) :
Inconsistent layout information in duplicated types (_PROPSHEETPAGEW):
(0x020000f4).
MainFrm.obj : error LNK2022: metadata operation failed (8013118D) :
Inconsistent layout information in duplicated types (tagTOOLINFOA):
(0x020001f1).
Finished merging metadata


I am at a complete loss here. I have no idea what to do. I follows the
LNK2022 suggestion and (ildasm -tokens).
I am at a loss as to what to look for in the results of (ildasm -tokens).
These structures (PROPSHEETPAGEA, PROPSHEETPAGEW) are actually single/double
byte #ifdef(s) in Win32 and we don't use them directly. We use
the MFC classes instead, CProperty***, CPropertyPage, etc..... I don't
understand why the linker complains about the ansi TOOLINFO and not the wide
one?
Again, we don't user this struct directly we use the MFC class instead.
When errors like this appear, do you have a check list of things to do that
will reveal why the linker complains?
If so may I have that list?
Can you please help with this newest problem?
Thank you,
Phnimx.

""Jeffrey Tan[MSFT]"" <jetan@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:s0q3FIHMHHA.2488@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi Phnimx,

Yes, this newsgroup is more suitable for this question than CLR newsgroup,
although I have also provided a reply to you in the CLR newsgroup :-). I
paste my reply below for your information:

"This is a common problem in managed C++ by mixing unamanged and managed
code. The key point is that some header file includes "using namespace
System;" statement which makes names from the System namespace accessible
to the entire program. However, windows.h indirectly contains #include
servprov.h, which has the following declaration:
"typedef interface IServiceProvider IServiceProvider;"

The IServiceProvider becomes an ambiguous symbol.

The link below talks about this problem in details:
"Managed Extensions for C++ Migration Guide--Ambiguous References"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/ht
ml/vcmg_ambiguousreferences.asp

You may follow the resolution in the link to move "#include <windows.h>"
to
the top.

MFC application may use some more complex header files including, in which
case you do not use any IServiceProvider directly in code. If the the
resolution in the link does not work for you, you may try to find "using
namespace system" in MCDll.h and move it below the #includes in MCDll.h.
This should fix the problem.

Please feel free to let me know the result. Thanks."

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.



.