-2

I am new to C# and modifying my first big program. I keep getting the following and and I am unsure how to New it up your help would be greatly appreciated

baseErrorCodes = New List(Of String)()
Dim errorCodeDescription As String = String.Empty
Dim baseCode As String
For Each errorCode As String In errorCodes
    Dim matchingBusinessRuleByResponseCode As BusinessRule = Me.DomainData.Common.BusinessRules _
        .FirstOrDefault(Function(businessRule) (businessRule.ApplicationSource = Me.BusinessRuleSource _
                                OrElse businessRule.ApplicationSource = "Maryland") _
                            AndAlso businessRule.ResponseCode = errorCode)

    baseCode = errorCode.Split("-")(0)
    If (matchingBusinessRuleByResponseCode IsNot Nothing) Then
        If (String.IsNullOrWhiteSpace(fieldSource)) Then
            fieldSource = matchingBusinessRuleByResponseCode.FieldSource
        End If

Error Message

Error Message

John Alexiou
  • 28,472
  • 11
  • 77
  • 133
zwheeler
  • 1
  • 1

1 Answers1

0

So errorCode is null. This is the result of not finding a match and the default for string type is null. This is the expected behavior of .FirstOrDefault().

To fix, add a check If errorCode IsNot null Then ... before calling .Split().

or use String.IsNullOrEmpty() to handle.

John Alexiou
  • 28,472
  • 11
  • 77
  • 133