code not cls-compliant

Posts   
 
    
Posts: 1268
Joined: 10-Mar-2006
# Posted on: 31-Oct-2006 02:47:42   

In a class library I have a class that exposes a couple of Entities as properties:


private CompanyEntity _test;
public CompanyEntity Test
{
    get
    {
        if (_test == null)
        {
            _test = new CompanyEntity();
        }
        return _test;
    }
}

When compilign this code, I get a warning cs3003: Type of FullClassName.Test is not CLS-compliant. It does not give a reason why or anything. I tried a couple of different entities and it gave the error each time.

Why is this?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-Oct-2006 06:56:07   
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 31-Oct-2006 08:45:58   

This means the entity 'CompanyEntity' isn't CLS compliant, so you added something to that class which breaks the cls compliance, e.g. adding a uint typed property.

The generated code made by llblgen pro is CLS compliant.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1268
Joined: 10-Mar-2006
# Posted on: 31-Oct-2006 16:26:10   

The property I exposed is from a new table I just created in my database, just mapped in LLBLGen and just generated code for - no modifications!

If I have added other code to other entities that made them non-compliant, would that in turn make the entire assembly non-compliant - then using any class from there give this warning? If that is not true - then I am unsure as it is straight generated code...

To track this down and to avoid this completely in the future, I think a few changes to the templates would be good:

In the AssemblyInfo.cs file for the LLBLGen generated project:

[assembly: System.CLSCompliant(true)]

and then on every class:

[CLSCompliant(true)]

This way, we would get an error when compiling if the user did something non-compliant.

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 01-Nov-2006 03:14:42   

Update - I put the items above into the templates, regenerated, recompiled and the warning no longer shows...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 01-Nov-2006 09:03:21   

ah, I thought these were already added and the code broke these attributes.

Yes, if you compile assembly A with these attributes and in A you reference a type of assembly B and B isn't compiled with these attributes, A can't be cls compliant. I run into this with the DB2 provider code, as that provider isn't CLS compliant and the vb generated code throws a warning because of this.

It's an oversight in the C# templates. In the vb.net templates, this attribute is present. I'll add the attribute to the assemblyinfo class template for C#.

(edit) You don't need to have the attribute on every class, just on the assembly.

Frans Bouma | Lead developer LLBLGen Pro