2

I have a main application, which loads plugins from "./plugins" directory.

The plugins are library assemblies containing UserControls, which use some images (resources).

The problem is that the images are not found when used in the main application.

XamlParseException -> Cannot locate resource 'X.png'

I tried building the resources as "Resource", "Embedded Resource" and "Content", but the exception still persists.

I tried specifying the path to images as

/X.png

and also as (neither works)

pack://application:,,,/<PluginAssemblyName>;X.png

How should I build the image resources so that they are available even after loading the assembly as plugin?

svecon
  • 554
  • 1
  • 5
  • 8

4 Answers4

1

Have you looked at this example? The Assembly would be the one you've loaded programmatically.

Also take care and make the resource accessible (much like a class is declared public), otherwise it cannot be referenced from outside the assembly.

More about it on MSDN.

pid
  • 11,472
  • 6
  • 34
  • 63
  • There is no way to set the image resource as public, or am I missing something? – svecon Apr 16 '15 at 18:59
  • No, you are not missing something. What I meant was declaring it *accessible* which is *as if* a `class` is made `public`. For images I've added an edit above to explain how to do it, but I guess this is not your concern anymore as you've solved the problem on your own :) – pid Apr 16 '15 at 22:03
1

Set the as Resource and try to use the below pack URI syntax. For the resources in the other assembly you should use the /AssemblyName;component syntax

"pack://application:,,,/AssemblyName;component/x.png"
Ayyappan Subramanian
  • 5,348
  • 1
  • 22
  • 44
0

You can use Assembly.GetManifestResourceNames to get a listing of all the resources and the names they have, which will let you know what name(s) to use to retrieve your resource(s).

DWright
  • 9,258
  • 4
  • 36
  • 53
  • I tried this, but the images were not listed there, only "WpfApp.g.resource" and "WpfApp.Properties.Resources.resources". – svecon Apr 16 '15 at 18:58
0

Found an answer to my problem here: https://stackoverflow.com/a/2416464/2649340

In the plugin assembly I use this path to reference the image resource

"/«YourAssemblyName»;component/«YourPath»/«YourImage.png»"

and even while this plugin is loaded in another assembly, it loads correctly.

Community
  • 1
  • 1
svecon
  • 554
  • 1
  • 5
  • 8