Search code examples
winformsvisual-studiodebuggingioexceptionimage-load

System.IO.FileNotFoundException in debug but not with exe


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?


Solution

  • I use this:

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

    and it works perfectly