Question

I'm using LINQ to SQL as my data access layer for a new project. I have added my database tables to the designer and all is well.

Whenever I use one of these classes in a function, Visual Studio warns me that 'Type xxxx is not CLS-compliant' or that 'Return type of function xxxx is not CLS-compliant'

Is this a problem with the classes that LINQ to SQL generates? Does it matters? Can I disable these warnings anywhere? My VS error list is clogged up with these warnings making it hard to see anything else.

EDIT:

Sorry, I should have mentioned these are VB.NET projects. :)

Was it helpful?

Solution

Ben M has the right idea on the problem.

The quickest way to solve this on a VB.Net project is to make the assembly not CLSCompliant and hence avoid those warnings. Adding the following line to any of your files will do the trick

<Assembly: CLSCompliant(False)>

Best file to add it into is AssemblyInfo.vb inside of the "My Project" folder.

OTHER TIPS

I found this link on MSDN Connect:

When adding inheritance relations between classes in the O/R designer, the acess level on the generated backing store member of the Id attribute, "_Id", is changed from private to protected, causing the CLS rule violation. The Id property is used in an association between the classes.

If you want to get rid of the warnings, you can use:

#pragma warning disable 3021

Or, if you want to disable them project-wide, add 3021 to the "Suppress warnings" field in the Build tab of your project's properties in Visual Studio.

It ultimately depends on what types are being returned by your database and what the names of those types are.

One issue regarding CLS compliance is a type that has two publicly exposed members which differ in name only by case, e.g. MyField and myField.

Here's an article that should help you determine where your CSS compliance issues are occuring and deal with the issues. If you need more help, pose some code and we'll see what we can do.

I usually see that error when I'm consuming types from one assembly which does not have the CLSCompliant attribute in another assembly which does.

That is, are your Linq to SQL classes in a different project than the functions you're writing? Have you specified [assembly: CLSCompliant(true)] in some but not all of the projects in your solution?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top