Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SplashScreen IOException

SplashScreen s = new SplashScreen(System.Reflection.Assembly.GetExecutingAssembly(),"splash.png");
s.Show(false);

when invoking s.Show() whether the parameter is false or true, it throws an IOException with the message

Cannot locate resource 'splash.png'

even though that splash.png is added to resources and its Build Action is Resource.

I have noticed many problems when using images in WPF, also with Image control.

like image 367
Jalal Mostafa Avatar asked Oct 25 '14 11:10

Jalal Mostafa


2 Answers

According to the principle "My Code doesn't work and I don't know why. My code Works and I don't know why", I have solved the problem.

First I have made the Build Action of the splash image as Resource. (Putting the image as Embedded Resource didn't solved the problem).

Second, My code is :

SplashScreen s = new SplashScreen("resources/splash.png");
s.Show(false);
/* do some things */
s.Close(Timespan.FromMilliseconds(300));
like image 192
Jalal Mostafa Avatar answered Sep 22 '22 22:09

Jalal Mostafa


even though that splash.png is added to resources and its Build Action is Resource.

Wrong build action, make it Embedded Resource. If you still have trouble then use ildasm.exe to look at the assembly manifest for the .mresource directive to ensure that the resource got properly embedded with the expected name.

Or use a file, following these how-to steps. Generally the more sane approach since it doesn't make that much sense to have a large resource occupy address space for the life of the program when it is only needed for a short amount of time at the start of the program.

like image 28
Hans Passant Avatar answered Sep 20 '22 22:09

Hans Passant