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.
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));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With