Merging ResourceDictionary from referenced assembly fails to compile
See original GitHub issueDescription
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
- Create new MAUI app
- Add new MAUI Class Library and reference of it to App project
- Add ResourceDictionary.xaml to Class Library project
- Add this resource dictionary to App.xaml like this
<ResourceDictionary Source="pack://application:,,,/TRGT.Core.Platform;component/CommonResources.xaml"/>
- Try to compile
- 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:
- Created 2 years ago
- Reactions:1
- Comments:26 (15 by maintainers)
I think you just add it using the type name. For example, assume you have some dictionary
MyResources
, then you can just add it: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