user1532468
user1532468

Reputation: 1753

VS 2010 Name is not CLS-compliant error

I have tried several ways to find a solution to this problem and have come up blank. Hence the post. I am using visual studio 2010 and building an application using VB and when I run(debug) I get the following errors.

A field in the dataset ‘DataSet1’ has the name ‘Invoice address’. Field names must be CLS-compliant identifiers.

There are many of these pointing to the dataset and quite frankly, I am not sure how go about solving it. I have used: <Assembly: CLSCompliant(False)> in AssemblyInfo.vb but still the errors come. I read somewhere that this line is to be put in a file AssemblyInfo.cs. I do not have one of those. Any help with this would be greatly appreciated. Thanks

Upvotes: 2

Views: 10991

Answers (1)

IvanH
IvanH

Reputation: 5139

The CLSCompliant does not work in this case. The problem is that the field name Invoice address contains a space and so the identifier is not CLS compliant (Why is this name with an underscore not CLS Compliant?).

The context is not stated in the question, but this error often occurs in RDK reports.

The Report Designer solves the problem by renaming fields

<Field name="non_CLS_Compliant_Name">
 <DataField>non CLS Compliant Name</DataField>
 </Field> 

In code you should replace all non compliant characters in names with underscore (_) and add ID at the beginning to solve problems with the first character

Dim RgxGlobal As New System.Text.RegularExpressions.Regex("[^\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Cf}]")
Dim RgxStart As New System.Text.RegularExpressions.Regex("\A[^\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]")
Dim NewFieldName As String = RgxGlobal.Replace(ColName, "_")
If RgxStart.IsMatch(NewFieldName) Then NewFieldName = "ID" & NewFieldName 

Upvotes: 5

Related Questions