views:

420

answers:

4

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. :)

A: 

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.

Randolpho
+3  A: 

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.

Ben M
Hmmm, closed with a "Won't fix"....looks like I'm just gonna have to try and filter them out.
Nick
A: 

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?

bdukes
Yes the DBML file is in a separate project from the functions that have the warnings on.I haven't specified CLSCompliance anywhere but from reading around it seems that VB.NET does this automatically for Class Library projects.
Nick
+2  A: 

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.

JaredPar
Excellent, that's the information I was looking for. Strangely it wasn't the project with the DBML file in that was set to be CLSCompliant but the MSTest project that referenced it. Thanks to everyone for their help.
Nick