I have a WPF application that should be able to load predefined Uri based UserControl . I use Application.LoadComponent(Uri) for this, but now it throws an IOException with Cannot locate resource...
My original architecture looked just 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 to another assembly that is not directly referenced by the Application Assembly (since this second assembly will reference the Application Assembly , so the link will be circular; there may also be additional assemblies that are not known in compilation time for the main application, so this, unfortunately, is a specific requirement).
I fixed it, and now everything looks like this:
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 create an instance of Custom Control.xaml (via 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 the same path to the dynamically added control is passed. The paths (inside the assembly) have not changed, and I tried both:
Application.LoadComponent("Dynamically Loaded Control.xaml");
and
Application.LoadComponent("Third Assembly;Dynamically Loaded Control.xaml");
And, unfortunately, both give the same result. The only problem I can think of is the fact that user and dynamic controls are now in an assembly that loads explicitly and not via a link, but I'm not sure why this matters.
How can I get Application.LoadComponent to properly load a component that is compiled into an assembly that I load explicitly at runtime?