Alex Rivera | Logout

WPF control throwing 'resource identified by the URI missing' exception

Asked 2011-02-14T14:08:41.280
18

On loading the plugin and trying to create 'XYZ' control, the application throws the following exception:

"The component 'XYZ' does not have a resource identified by the URI '/ThePluginAssembly;component/XYZ.xaml'" on the InitializeComponent() method in the UserControls constructor.

The key points are:

  1. The user control is located in the plugin assembly

  2. I am trying to create the usercontrol from inside the plugin assembly

  3. The plugins are located in the same directory as the main application

  4. The user controls only have problems when they are created through XAML. I have a couple of other usercontrols in the same assembly but I instantiate these using code. I only receive the error message when I attempt to create a UserControl in XAML.

On doing some google, i realized that this happens when two instances of my plugin are loaded in the application. When i removed my plugin from one of the folders ( I allow this plugin to be loaded from two locations) this exception stopped recurring.

My questions:

1) What is the reason behind WPF trying to resolve a URI to load my control?

2) Isn't there a way by which i could have two instances of my plugin loaded in the application and somehow get rid of this exception? or some way to create a unique URI for each instances (if this exception is caused by a conflicting URI).

Any comment or reference would be of help.

Thanks for your interest.

Edit: Same problem as posted by Phil : How to force WPF to use resource URIs that use assembly strong name? Argh!

Edit
Report

1 Answer

1

The following directions are relevant for both the plugin's assembly and any non-System assembly referenced by the plugin (duplication could be at any level of references).

Since the plugin's assembly is located in the application's executable directory,
if you added your assembly to the GAC, remove it from there.

Check all references to the assembly from your solution and set "Version Specific" to false.

If the plugin assembly is from another solution and you use different versions of the assemble for debug/release or for x86/x64 then edit the .csproj files that reference the assembly and set a reference path like in this example.

Consider canceling reference to plugin assemblies and using reflection to load them instead - this will remove dependencies of solution upon plugins.
To do this, you will need to move any code that looks for specific elements in plugins to the plugin assemblies themselves and from original solution only access types exposed by plugin that support interfaces defined outside the plugin (by assemblies in original solution or in an assembly referenced by both original solution and plugin).
- While accessing assembly via reflection, make sure that you load the assembly from the application's executable directory.

Make sure the Pack URIs to resources are of the form: "pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml"

answered 2011-03-07T11:55:14.363

Your Answer