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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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?)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.