System.IO.FileNotFoundException in debug but not with exe

1k views Asked by At

I'll try to be simple and quick

I'm developing a program, a windows form actually. I have a pictureBox and in the following line, when I run in debug mode(note that), I get an System.IO.FileNotFoundException exception:

pictureBox1->Image = Image::FromFile(".\\images\\no-avatar2.jpg");

The problem is that I don't get that exception when I run the exe file AND the file loads perfectly. Any ideas why this happens?

1

There are 1 answers

0
Poniros On BEST ANSWER

I use this:

pictureBox1->Image = Image::FromFile(System::IO::Path::GetDirectoryName(System::Reflection::Assembly:‌:GetEntryAssembly()->Location) + "\\images\\no-avatar2.jpg");

and it works perfectly