Search code examples
c#.netc++-climixed-mode

Unable to use properties from C++/CLI interface


I have a mixed mode C++/CLI class and interface that I want to use from C#. The interface is defined like this:

public interface class IMapRenderingInterfacer 
{
    ...
    property int CurrentCacheSize { int get(); };
    ...
};

The implementation class has this declaration in its header file:

public ref class MapRenderingInterfacer : public IMapRenderingInterfacer
{
   ...
public:
    virtual property int CurrentCacheSize { int get();  }
   ...
};

And the implementation of the property is in the cpp file:

int MapRenderingInterfacer::CurrentCacheSize::get()
{
    return (*_nativeMapRenderingInterface)->getCurrentCacheSize()/1000000;
}

This compiles without errors or warnings, but when I try to use this property from a C# class, I get the following error:

Error CS1061 'IMapRenderingInterfacer' does not contain a definition for 'CurrentCacheSize' and no extension method 'CurrentCacheSize' accepting a first argument of type 'IMapRenderingInterfacer' could be found (are you missing a using directive or an assembly reference?)

This interface also contains a number of methods that I can use just fine from C#, but not this property.

Any ideas?


Solution

  • Hans Passant had it right! It was simply a project reference that pointed to the wrong version of the mixed mode assembly. Removing and adding the reference again in the project did the trick!