Avatar of CalmSoul
CalmSoul
Flag for United States of America asked on

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

I have a vb.net code which reads from a text file all network locations and then calculated the MD5 hash of those files and then further write hash values to output.txt file ... Program stops working after 500 lines and throw following error ... following is the code and error messages

CODE:
        Dim sNames As String() = {"A"}


        System.Threading.Tasks.Parallel.For(0, sNames.Count, Sub(i)

                                                                 For Each line As String In lines
                                                                     file.Write(MD5(line, 2))
                                                                     file.Write("@")
                                                                     file.WriteLine(line)
                                                                     ' i += 1

                                                                     ProgressBar1.Value += 1

                                                                 Next
                                                             End Sub)




        file.Close()

Open in new window



ERRORS:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
The program '[11208] WindowsApplication1.vshost.exe' has exited with code 0 (0x0).

Open in new window

Visual Basic.NET.NET ProgrammingC#

Avatar of undefined
Last Comment
sarabande

8/22/2022 - Mon
Bob Learned

First chance exceptions are difficult to find a reason for, and are not thrown, and in my opinion they can be ignored.
CalmSoul

ASKER
@Bob, but program stops how can I ignore and proceed in my code?
SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CalmSoul

ASKER
it just prints "60" and nothing happens - no exception ... on output file it just stops writing ...
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SOLUTION
Jacques Bourgeois (James Burger)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
sarabande

do you close the files afetr they were written? windows applications have a maximum of 512 file handles that can be opened same time. this maximum can be increased to 2048 (programmatically) but it is better to practice a proper closing of your files.

Sara
CalmSoul

ASKER
sarabande:

Interesting, so where should I close them with in the loop after every line write?
ASKER CERTIFIED SOLUTION
sarabande

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.