BC42017 Late bound resolution; runtime errors could occur

Shahab a 261 Reputation points
2024-07-12T14:19:11.0966667+00:00

Hello friends,

I am programming with VB.NET 2022. In this line of code:

With BsQRequestPorductHeader

TxtRequestPorductHeaderId.Text = .Current.Item("RequestPorductHeaderId").ToString

TxtRequestPorductHeaderNum.Text = .Current.Item("RequestPorductHeaderNum").ToString
```End With

I have this error:

Severity Code Description Project File Line Suppression State Warning (active) BC42017 Late bound resolution; runtime errors could occur.

How do you think I can fix this error?

![aa](/api/attachments/af8782b4-629b-4f58-ad7b-a721cbaf2f54?platform=QnA)

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,660 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 28,946 Reputation points Microsoft Vendor
    2024-07-15T01:38:34.5366667+00:00

    Hi @Shahab a

    You should ensure that the types are explicitly defined.

    Make sure the BsQRequestPorductHeader is properly typed and its type includes the Current property with the required items.

    Try
        ' Assuming BsQRequestPorductHeader is a BindingSource or similar object
        If BsQRequestPorductHeader.Current IsNot Nothing Then
            ' Explicitly cast the items to the appropriate types
            Dim requestPorductHeaderId As Byte = Convert.ToByte(BsQRequestPorductHeader.Current("RequestPorductHeaderId"))
            Dim requestPorductHeaderNum As String = BsQRequestPorductHeader.Current("RequestPorductHeaderNum").ToString()
    
            TxtRequestPorductHeaderId.Text = requestPorductHeaderId.ToString()
            TxtRequestPorductHeaderNum.Text = requestPorductHeaderNum
        Else
            TxtRequestPorductHeaderId.Text = String.Empty
            TxtRequestPorductHeaderNum.Text = String.Empty
        End If
    Catch ex As InvalidCastException
        MessageBox.Show("Error converting data: " & ex.Message)
    Catch ex As Exception
        MessageBox.Show("An unexpected error occurred: " & ex.Message)
    End Try
    
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments