Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument Type is not CLS-compliant...class structure

Tags:

c#

I have a class as follows...The idea is to do some logic processing and return a read only object.

public class Test
{
    public object property1 { get; private set; }
    public string property2 { get; private set; }


    private Test(){}

    public static Test GetTest(XDocument document)
    {
        if (document== null)
            return null;

        return new Test 
        {
            property1 = l_document.Element("something").value,
            property2 = l_document.Element("anotherthing").value,
        };
    }
}

If I use the above test object as paramerter in a function, I get a message Argument Type is not CLS-compliant... Any suggestions? Any other way I can achieve a read only object?

Thanks, Kamar

like image 934
Kamar Avatar asked Dec 28 '22 15:12

Kamar


1 Answers

EDIT: (Removed previous answer.)

Having tried this myself, I strongly suspect that it's just a matter of you not putting [assembly:CLSCompliant(true)] in the assembly declaring the Test class. Do that, and all should be peachy.

like image 164
Jon Skeet Avatar answered Dec 31 '22 04:12

Jon Skeet