#1,109 – Accessing a Resource in a Different Assembly

You can use the following URI, in code, to access a resource embedded into the executing assembly.

                    BitmapImage bmi = new BitmapImage(new Uri("pack://application:,,,/Images/Ted.jpg"));

If you want to access a resource in a different assembly, you use the Uri syntax shown below, adding the assembly name and the word “component”.

                    BitmapImage bmi = new BitmapImage(new Uri("pack://application:,,,/MyPictures;component/Ted.jpg"));

This assumes that the image Ted.jpg is included in an assembly named MyPictures (e.g. in MyPictures.dll).  It also assumes that the Build Action for the image is set to Resource and that this assembly is in the same directory as the executing assembly.  If you want the resource assembly to end up in the same output directory as the main assembly, you’ll want to add a reference to it from the main assembly.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: