I've been trying to develop a C++/CLI library for use in C# and I have the following problem. If we take my managed reference class to be as follows:
namespace Library
{
using namespace System;
public ref class Test
{
internal:
String^ internalString;
public:
Test()
{
internalString = gcnew String("Hey There");
}
~Test()
{
}
};
public ref class TestImplement
{
public:
static String^ TestMessage(Test test)
{
return test.internalString;
}
};
}
And my C# implementation as follows:
using System;
namespace AddProgram
{
class Program
{
static void Main(string[] args)
{
Library.Test test = new Library.Test();
Console.WriteLine(Library.TestImplement.TestMessage(test));
Console.Read();
}
}
}
I get the following error:
error CS0570: 'TestMessage' is not supported by the language
As far as I can tell this is due to passing the type Library.Test as an argument. I don't understand why I am getting this message, and I hope it is possible to pass types from my reference library .
Any help would be appreciated
You need to declare TestMessage as taking a reference to a Library.Test, which means using the caret (^) like you did for String^. C++/CLI allows you to handle reference types using value type semantics (sort of) by leaving off the caret, but C# has no equivalent feature, which is why you're getting that error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With