I have a WPF application that needs to be able to load predefined UserControl
s based upon a Uri. I'm using Application.LoadComponent(Uri)
to do this, but it's now throwing an IOException
with Cannot locate resource...
.
My original architecture looked like this and worked as expected:
Application Assembly/
Main Window.xaml
Custom Control.xaml
Dynamically Loaded Control.xaml
Second Assembly/
Class that executes Application.LoadComponent("Dynamically Loaded Control.xaml")
However, I need to be able to move Custom Control
and Dynamically Loaded Control
into another assembly that is not directly referenced by Application Assembly
(as this second assembly will reference Application Assembly
, so the reference would be circular; there may also be additional assemblies that are not known at compile time for the core application, so this is unfortunately a definite requirement).
I've rearchitected it and things look like this now:
Application Assembly/
Main Window.xaml
Second Assembly/
Class that executes Application.LoadComponent("Dynamically Loaded Control.xaml")
Third Assembly
Custom Control.xaml
Dynamically Loaded Control.xaml
I can dynamically instantiate Custom Control.xaml
(by way of a custom DataTemplateSelector
) after loading Third Assembly
by file name and this works as expected. However, the class in Second Assembly
now throws the above exception when getting passed the same path to the dynamically added control. The paths (within the assembly) have not changed, and I have tried both:
Application.LoadComponent("Dynamically Loaded Control.xaml");
and
Application.LoadComponent("Third Assembly;Dynamically Loaded Control.xaml");
And unfortunately both produce the same result. The only issue I can think of is the fact that the custom and dynamic controls are now in an assembly that is loaded explicitly rather than via reference, but I'm not certain why that would make a difference.