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

前端 未结 3 1908
南方客
南方客 2021-02-12 18:13

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

\"The component \'XYZ\' does not have a reso

相关标签:
3条回答
  • 2021-02-12 19:06

    The only way to do this would be to include the version information in your URI, so the XAML loader can distinguish the correct type. This MSDN article explains the Pack URI format, and the Version portion has this description:

    ;Version [optional]: the version of the referenced assembly that contains the resource file. This is used when two or more referenced assemblies with the same short name are loaded.

    So you'd want to use one of the following:

    /ThePluginAssembly;v1.0.0.0;component/XYZ.xaml
    /ThePluginAssembly;v1.1.0.0;component/XYZ.xaml
    
    0 讨论(0)
  • 2021-02-12 19:07

    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"

    0 讨论(0)
  • 2021-02-12 19:08

    try to use Assembly.LoadFrom() instead of Assembly.Load() or Assembly.LoadFile().

    I had the same problem: I used to load assemblies with Assembly.LoadFile(). After searching for days, I found out that Assembly.LoadFile() and Assembly.Load() are deprecated. Both methods create problems in the runtime. So I used Assembly.LoadFrom() and it worked.

    0 讨论(0)
提交回复
热议问题