Why is this an issue?

Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.

Exceptions

The following are ignored:

How to fix it

Use constants to replace the duplicated string literals. Constants can be referenced from many places, but only need to be updated in a single place.

Code examples

Noncompliant code example

Public Class Foo

    Private Name As String = "foobar" ' Noncompliant

    Public ReadOnly Property DefaultName As String = "foobar" ' Noncompliant

    Public Sub New(Optional Value As String = "foobar") ' Noncompliant

        Dim Something = If(Value, "foobar") ' Noncompliant

    End Sub

End Class

Compliant solution

Public Class Foo

    Private Const Foobar As String = "foobar"

    Private Name As String = Foobar

    Public ReadOnly Property DefaultName As String = Foobar

    Public Sub New(Optional Value As String = Foobar)

        Dim Something = If(Value, Foobar)

    End Sub

End Class