I know there are several answers about this, but they do not cover my specific case! Please check before closing the question.
- Other answers:
- resource used before being defined (not my case)
- another, same as above
- use x86 architecture (didn't work for the referenced assembly, cannot change the main assembly)
- My problem: resource fails when loaded from another assembly, but works ok if loaded from the main project assembly
I have a DLL project that references a Utils.WPF
project (also DLL). The referenced project is supposed to have many WPF objects such as converters, commands, etc.
If I try to use a converter from the Utils.WPF assembly, I get this exception at run time:
Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll Additional information: 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '22' and line position '18'. occurred
Line 22 is where I use the converter:
<Window x:Class="MainNameSpace.WpfSelectODAttributes"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MainNameSpace"
xmlns:wpf="clr-namespace:Utils.WPF;assembly=Utils.WPF"
mc:Ignorable="d"
Title="Selecione os atributos desejados:" Height="450" Width="400">
<Window.Resources>
<wpf:BoolVisibilityCollapseConverter x:Key="BoolToVisible"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding Items}"
Visibility="{Binding HasItems, Converter={StaticResource BoolToVisible}}"
Grid.Column="0" Margin="10">
.............
But if I use exactly the same code, but declaring the converter within the main project (inside MainNameSpace
, changing wpf:
with local:
in the xml when declaring the resource), the program runs fine.
I tried compiling the Utils.WPF
code as AnyCPU
, x64
and x86
to no success.
PS: the main project is project is obliged to be x64
.
Is there any solution I might be missing?