Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My own managed type as arg in C++/CLI class library : CS0570: is not supported by the language

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

like image 329
xcvd Avatar asked Dec 28 '11 21:12

xcvd


1 Answers

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.

like image 66
MikeP Avatar answered Oct 31 '22 08:10

MikeP