简体   繁体   中英

VB.net CA1062 validate parameter

Working on an old .net 3.5 vb web application Getting over 1000 warnings on public property methods such as the following CA1062 : Microsoft.Design : In externally visible method 'TheClass.TheMethod.Set(String)', validate parameter 'value' before using it.

Original:

Public Property DealerBMRName() As String
    Get
        Return hdBMRName.Value
    End Get
    Set(ByVal value As String)
        hdBMRName.Value = value.Trim()
    End Set
End Property

modified yet still throwing the error:

Public Property DealerBMRName() As String
    Get
        Return hdBMRName.Value
    End Get
    Set(ByVal value As String)
        If value Is Nothing Then
            hdBMRName.Value = ""
        Else
            hdBMRName.Value = CStr(value)
        End If
    End Set
End Property

Pretty sure I am following MSDN suggested workaround: http://msdn.microsoft.com/en-us/library/ms182182(v=vs.100).aspx

Any ideas what I might be missing apart from the fact that the code itself is ugly? I can't remove the error even with something as basic as:

Set(ByVal value As String)
    hdBMRName.Value = "SomeValue"
End Set

Using VS2010 and resharper.

The issue resolved itself when I fixed a bad line entry in my web.config. It had nothing to do with the error but may have been throwing the issue. PS: I needed to use .Value as the object is an asp:hiddenField.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM