C++/CLI Interface is not visible from my C# Class

Dzyann

I have an interface in C++/CLI I need to implement in C#, but I it is not visible. However I have other classes (abstract and concrete that I can inherit from).

My C++/CLI Interface:

namespace MyNamespace { namespace MySubnamespace { 

public interface class ITestInterface
{
public:
    property bool FirstProperty
    {
        bool get();
    }

    property bool SecondProperty
    {
        bool get();
    }

};

}}

I have a Test project where I use all the functionality in my Managed Library, but the Interface never becomes visible.

How I try to use it in my C# Test project: (I tried using it from a Class Library Project also, and it doesn't work either).

public class Test: MyNamespace.MySubnamespace.ITestInterface
{

}

I get "Cannot resolve symbol 'ITestInterface'"

What am I missing?

Update

I kept trying different things following the comments to my question, and I found that if I include my .h file in some other .h file of my C++/CLI project, the class becomes visible. Basically I just do:

#include "ITestInterface.h"

In one of my other .h files of the C++/CLI project and the Class becomes visible to the c# project.

Is there a way I could avoid doing that?

crashmstr

C++/CLI is similar to C++ in that only .cpp files are compiled directly. Header files are only compiled when included. This is why adding an #include for your interface header works.

There are several ways to make sure your code is included for a C++/CLI class:

  • Have both a .h and .cpp file (even if the .cpp file only includes the .h file it corresponds to)
  • Have only include files and then include all of the headers in one .cpp file (which may be empty other than the includes)
  • Have only .cpp files (which is fine if the other code does not reference this code)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C++/cli interface with properties not usable from c#

From Dev

CLI/C++ Interface class, Generic method calling template method

From Dev

CLI/C++ Interface class, Generic method calling template method

From Dev

Self-referencing class: concrete python class from C interface

From Dev

C++ Invalid conversion from interface class to child class

From Dev

Implement a generic C++/CLI interface in a C# generic interface

From Dev

Implement a generic C++/CLI interface in a C# generic interface

From Dev

Can a C++ interface inherit from a class with full implementation?

From Dev

Inhereting a virtual class interface from a DLL (C++)

From Dev

Casting a Generic Class<T> in C# from an Interface?

From Dev

c# Is there a way that my base class and derived class can implement Interface methods separately?

From Dev

C#: my derived class cannot override base class's interface method implementation, why?

From Dev

c# Is there a way that my base class and derived class can implement Interface methods separately?

From Dev

C# interface and class inheritance

From Dev

Wrapping C++ CLI Class For C#

From Dev

Wrapping C++ CLI Class For C#

From Dev

C# Interface Error: There is no implicit reference conversion from class xxx to interface xxxx

From Dev

Class Design with Generic Class and Interface in C#

From Dev

In C#, how can I refer to a typedef from a C++/CLI class

From Dev

In C#, how can I refer to a typedef from a C++/CLI class

From Dev

Objective-C error: No visible @interface declares the selector

From Dev

objective c error "No visible @interface for 'NSString' declares the selector 'timeIntervalSinceDate:'"

From Dev

Implementing my own array from a template class in C++

From Dev

Calling a C# class from my ASPX page

From Dev

Porting from C++ to C++/CLI

From Dev

Array not allowed in class in C++/CLI?

From Dev

Opening up a CLI version of my code from within window form in c#

From Dev

How do I return a managed string from a C++/CLI class

From Dev

C# Specialize generic interface from inherited interface in derived interface

Related Related

  1. 1

    C++/cli interface with properties not usable from c#

  2. 2

    CLI/C++ Interface class, Generic method calling template method

  3. 3

    CLI/C++ Interface class, Generic method calling template method

  4. 4

    Self-referencing class: concrete python class from C interface

  5. 5

    C++ Invalid conversion from interface class to child class

  6. 6

    Implement a generic C++/CLI interface in a C# generic interface

  7. 7

    Implement a generic C++/CLI interface in a C# generic interface

  8. 8

    Can a C++ interface inherit from a class with full implementation?

  9. 9

    Inhereting a virtual class interface from a DLL (C++)

  10. 10

    Casting a Generic Class<T> in C# from an Interface?

  11. 11

    c# Is there a way that my base class and derived class can implement Interface methods separately?

  12. 12

    C#: my derived class cannot override base class's interface method implementation, why?

  13. 13

    c# Is there a way that my base class and derived class can implement Interface methods separately?

  14. 14

    C# interface and class inheritance

  15. 15

    Wrapping C++ CLI Class For C#

  16. 16

    Wrapping C++ CLI Class For C#

  17. 17

    C# Interface Error: There is no implicit reference conversion from class xxx to interface xxxx

  18. 18

    Class Design with Generic Class and Interface in C#

  19. 19

    In C#, how can I refer to a typedef from a C++/CLI class

  20. 20

    In C#, how can I refer to a typedef from a C++/CLI class

  21. 21

    Objective-C error: No visible @interface declares the selector

  22. 22

    objective c error "No visible @interface for 'NSString' declares the selector 'timeIntervalSinceDate:'"

  23. 23

    Implementing my own array from a template class in C++

  24. 24

    Calling a C# class from my ASPX page

  25. 25

    Porting from C++ to C++/CLI

  26. 26

    Array not allowed in class in C++/CLI?

  27. 27

    Opening up a CLI version of my code from within window form in c#

  28. 28

    How do I return a managed string from a C++/CLI class

  29. 29

    C# Specialize generic interface from inherited interface in derived interface

HotTag

Archive