Link to home
Create AccountLog in
Avatar of CalmSoul
CalmSoulFlag 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

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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

ASKER

@Bob, but program stops how can I ignore and proceed in my code?
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
it just prints "60" and nothing happens - no exception ... on output file it just stops writing ...
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
sarabande:

Interesting, so where should I close them with in the loop after every line write?
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.