Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I've got a managed C++ base assembly (BaseAssembly) that defines an interface:

// In MyInterface.h
namespace BaseAssembly
{
    public interface class IMyInterface
    {
        //...
    };
}


Two other managed C++ assemblies each contain a class that implements this interface:

// MyDerived1.h in managed C++ project MyDerived1Lib

#include "MyInterface.h";
namespace DerivedAssembly1
{
    public ref class MyDerived1 : public BaseAssembly::IMyInterface
    {
        //...
    };
}

// MyDerived2.h in managed C++ project MyDerived2Lib

#include "MyInterface.h";
namespace DerivedAssembly2
{
    public ref class MyDerived2 : public BaseAssembly::IMyInterface
    {
        //...
    };
}


When I try to create an instance of IMyInterfaces in a separate C# app, I get error CS0433: The type BaseAssembly.IMyInterface exists in both MyDerived1.dll and MyDerived2.dll. Im not sure how to proceed.
Heres a snippet of the offending C# code:

// In MyClientApp.cs
namespace MyApp
{
    public class MyClientApp
    {
        public void Initialize()
        {
            IMyInterface impl = new MyDerived1();
        }
    }
}


The C# project references both derived assemblies. I've tried leaving the base assembly as a bare header file (i.e. not compiling it to a DLL), and compiling it to a DLL and referencing it from the C# project. Nothing seems to work. Thanks in advance for your help.
Posted
Updated 9-May-11 13:13pm
v2
Comments
HimanshuJoshi 9-May-11 19:13pm    
Edited to add pre tags around code.

Try to use
#pragma once
in the header file MyInterface.h.

That might solve the problem.
 
Share this answer
 
Comments
Olivier Levrey 10-May-11 5:04am    
This will not help at all. OP is facing a problem C# side...
There are 2 options:

1- Create a nother dll which will contain your base interface. And reference this dll in your other assemblies (the dll containing the derived classes implementing this interface, and the exe)

2- Make one of your existing dlls reference the other one which will contain the interface.
 
Share this answer
 

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