VS 2010 Name is not CLS-compliant error

10,845

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 
Share:
10,845

Related videos on Youtube

user1532468
Author by

user1532468

Updated on September 16, 2022

Comments

  • user1532468
    user1532468 over 1 year

    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

  • as9876
    as9876 over 8 years
    But the real question is why the VS Designer is auto-generating code that has bugs. Isn't that pathetic?