I'm trying to implement a native interface in C++/CLI, to a class developed in c#. I'm using VS2013.
Here's a simplified version of the C# class:
namespace ManagedTypes
{
public static class CaptureFile
{
public static IPacketList GetPackets() { new PacketList(); }
}
}
Here's the definition of the IPacketList interface:
namespace ManagedTypes
{
public interface IPacketList: IReadOnlyList<IPacket>
{
}
}
Just to be thorough, IReadOnlyList<T>
(in mscorlib) is declared as:
public interface IReadOnlyList<out T> : IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
{
T this[int index] { get; }
}
and IReadOnlyCollection<T>
(also is mscrolib) as
public interface IReadOnlyCollection<out T> : IEnumerable<T>, IEnumerable
{
int Count { get; }
}
So, from C#, I can do something like:
var n = CaptureFile.GetPackets().Count;
But if I try to do something similar from C++:
auto n = CaptureFile::GetPackets()->Count;
I get the following compilation error:
1>------ Build started: Project: MixedMode, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3274: The primary reference "C:\Hg\DP1000-DEV\src\Spikes\MixedModeSample\ManagedTypes\bin\Debug\ManagedTypes.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
1> MixedModeApi.cpp
1>MixedModeApi.cpp(9): error C2039: 'Count' : is not a member of 'ManagedTypes::IPacketList'
1> c:\hg\dp1000-dev\src\spikes\mixedmodesample\managedtypes\bin\debug\managedtypes.dll : see declaration of 'ManagedTypes::IPacketList'
1>MixedModeApi.cpp(10): error C3536: 'n': cannot be used before it is initialized
2>------ Build started: Project: NativeApp, Configuration: Debug Win32 ------
2>LINK : fatal error LNK1104: cannot open file 'C:\Hg\DP1000-DEV\src\Spikes\MixedModeSample\Debug\MixedMode.lib'
========== Build: 0 succeeded, 2 failed, 1 up-to-date, 0 skipped ==========
What am I missing here?