question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merging ResourceDictionary from referenced assembly fails to compile

See original GitHub issue

Description

I want to create ResourceDictionary in separate project, and reuse it in other projects, but when I try to add it to application resources, I getting compilation error. I’ve created simple .NET MAUI app (Main app), added another project as MAUI Class Library (Library project) and added reference to it to Main app. In Class Library, created custom ResourceDictionary file (CustomDictionary.xaml), added some styles to it. After that, to App.xaml I’ve added following to my application:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/SharedProject;component/CommonResources.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

But after compilation, I’m getting error “Invalid URI: Invalid port specified.” Even after I’ve changed it to pack://application:80,,,... still the same error. Same if adding this in App constructor: Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/SharedProject;component/CommonResources.xaml") });

Steps to Reproduce

  1. Create new MAUI app
  2. Add new MAUI Class Library and reference of it to App project
  3. Add ResourceDictionary.xaml to Class Library project
  4. Add this resource dictionary to App.xaml like this <ResourceDictionary Source="pack://application:,,,/TRGT.Core.Platform;component/CommonResources.xaml"/>
  5. Try to compile
  6. You getting error “Invalid URI: Invalid port specified.”

Version with bug

Preview 12 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

All

Did you find any workaround?

No response

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:26 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
mattleibowcommented, Jan 31, 2022

I think you just add it using the type name. For example, assume you have some dictionary MyResources, then you can just add it:

<Application xmlns:mine="assembly include here">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <mine:MyResources />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>
1reaction
ecasasnicommented, Jun 8, 2023

I tried 4398.zip from @XamlTest and was able to reproduce the issue in Visual Studio for Mac 17.5.6 (build 3). As @cmonto suggested, referencing a class from the SharedProject1 makes it work, but only if I use

<ResourceDictionary Source="CommonResources.xaml;assembly=SharedProject1" />
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Loading merged ResourceDictionary from different ...
Looking at the designer in VS all controls are displayed with the styles from the files but when I try to start the...
Read more >
WPF Merged Dictionary problems and solutions
This article will show how to: Use Merged Dictionaries in WPF to have application-wide resources that you can later use as a StaticResource...
Read more >
ResourceDictionary and XAML resource references
Merged resource dictionaries. A merged resource dictionary combines one resource dictionary into another, usually in another file. Tip You can ...
Read more >
How do you reference a XAML DictionaryResource from an ...
I've got an issue I'm trying to figure out with using ResourceDictionary and Merged Dictionaries. I've got WPF sample application that I've ...
Read more >
WPF Designer does not show content when using merged ...
I use custom ResourceDictionaries defined as Page XAML component which use static ... xmlns:sys="clr-namespace:System;assembly=mscorlib"
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found