[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Array.Find -- Object reference not set to an instance of an object

Posted on 2011-05-02
Medium Priority
Last Modified: 2013-11-26
I am trying to find filenames in a FileInfo Array
           WORKING_FILENAME = strDocFileName
            Dim DocFileFound As FileInfo
            DocFileFound = Array.Find(allArchiveDocs, AddressOf ContainsFileName)

                If DocFileFound.Length > 0 Then
                    dsCIAndArchiveData.Tables(0).Rows(i).Item("FullPath") = DocFileFound.FullName
                    dsCIAndArchiveData.Tables(0).Rows(i).Item("FullPath") = "NO FILE FOUND"
                End If
            Catch ex As Exception
                MessageBox.Show("Error finding File: " & ex.Message)
            End Try

Protected Function ContainsFileName(ByVal AllFileNames As FileInfo) As Boolean

        If AllFileNames.Name = WORKING_FILENAME Then
            Return True
            Return False
        End If

    End Function

Open in new window

This works, unless ContainsFileName cannot find the file which results in an "Object reference not set...(error in title)".  How can I check the DocFileFound before accessing?
Question by:frontback45
1 Comment
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 35506118
Try changing:

    If DocFileFound.Length > 0 Then


    If Not IsNothing(DocFileFound) Then

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question