SplashScreen IOException

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

when calling s.Show()whether the parameter is falseor true, it issues IOException with a message

Unable to find resource 'splash.png'

although this splash.png is added to resources, and its Build Action is Resource .

I noticed a lot of problems when using images in WPF, also using the control Image.

+4
source share
3 answers

In accordance with the principle "My code does not work, and I do not know why. My code works, and I do not know why," I solved the problem.

Action . ( Embedded Resource ).

-, :

SplashScreen s = new SplashScreen("resources/splash.png");
s.Show(false);
/* do some things */
s.Close(Timespan.FromMilliseconds(300));
+4

splash.png , - .

, Embedded Resource. , ildasm.exe, .mresource, , .

, . , , , , .

+1

try explicitly specifying the assembly name, even if the caller is in the same assembly as the resource.

Here's what it looks like with the package URI syntax:

pack://application:,,,/MyAssemblyName;component/MyResourcesFolder/MyImage.png

http://msdn.microsoft.com/en-us/library/aa970069.aspx

0
source

All Articles