vb.net VS 2010 名称不符合 CLS 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19208960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VS 2010 Name is not CLS-compliant error
提问by user1532468
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.
我尝试了多种方法来找到解决此问题的方法,但结果却是一片空白。因此该职位。我正在使用 Visual Studio 2010 并使用 VB 构建应用程序,当我运行(调试)时出现以下错误。
A field in the dataset ‘DataSet1' has the name ‘Invoice address'. Field names must be CLS-compliant identifiers.
数据集“DataSet1”中的字段名为“发票地址”。字段名称必须是符合 CLS 的标识符。
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
其中有很多指向数据集,坦率地说,我不确定如何解决它。我使用过:<Assembly: CLSCompliant(False)>在 AssemblyInfo.vb 中,但仍然出现错误。我在某处读到这一行将放在文件 AssemblyInfo.cs 中。我没有其中之一。对此的任何帮助将不胜感激。谢谢
回答by IvanH
The CLSCompliantdoes not work in this case. The problem is that the field name Invoice addresscontains a space and so the identifier is not CLS compliant (Why is this name with an underscore not CLS Compliant?).
该CLSCompliant不会在这种情况下工作。问题是字段名称Invoice address包含空格,因此标识符不符合 CLS(为什么带有下划线的名称不符合 CLS?)。
The context is not stated in the question, but this error often occurs in RDK reports.
问题中没有说明上下文,但此错误经常出现在 RDK 报告中。
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
在代码中,您应该用下划线(_)替换名称中所有不合规的字符,并在开头添加 ID 以解决第一个字符的问题
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

