generic error occurred in gdi+

For two out of the last ten files I used with the attached code, VB.NET returned this error.

Is there anything I could or should be doing in the code to avoid the problem?


Public Function ConvertFileToImage(ByVal fi_name As String, ByRef lex As LastException) As Boolean

        Dim img As System.Drawing.Image
        Dim retval As Boolean = True


            img = Image.FromFile(fi_name)

            If retval Then

                MyImage = img

            End If

        Catch ex As Exception
            retval = False
            lex.Message = ex.Message
            If Not ex.InnerException Is Nothing Then
                lex.Detail = ex.InnerException.Message
            End If
            lex.Source = "PageFileClass - ConvertFileToImage"
            lex.Code = "System Exception"

        End Try

        Return retval

    End Function

Open in new window

Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You aren't doing anything wrong in the code...

(1) The images have something wrong them
(2) You have some kind of access error (permissions or file in use?)
codefingerAuthor Commented:
Too bad.  If my code is OK, there is nothing else I can do.
But thanks for your answer, at least I won't waste any time on it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.