0

I know there are several answers about this, but they do not cover my specific case! Please check before closing the question.


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?

Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
  • What version of C#/.Net? Can you reproduce the error by creating your own third assembly with just that converter in just a test example project? Do you have access to that failure dll's code..if so what is line 22? – ΩmegaMan Feb 24 '21 at 02:58
  • Obviously the assembly was not loaded, therefore the reference to the converter type can't be resolved. You should have some warnings in your XAML when defining the converter, some squiggles. You would have to check and verify the context: *Is the assembly reference properly added to the project? *Does the projects reference folder shows a warning (yellow exclamation mark)? – BionicCode Feb 24 '21 at 09:39
  • *Are the current assembly and the referenced assembly compatible (framework and version)? *If the assembly is a project of the solution (and not imported as compiled DLL), then does it build properly? *If imported as DLL, are you missing dependencies of this DLL? *Have you tried 'Clean' followed by 'Rebuild'? Have you tried to set up a clean solution to try it in a clean environment? – BionicCode Feb 24 '21 at 09:39
  • What happens when you create an instance of a `BoolVisibilityCollapseConverter` in a class in the `AutomacaoDeProjetosEDUT` project where the window is defined? – mm8 Feb 24 '21 at 11:16
  • Well.... looks like the good-old "restart computer" solved this problem. Thank you for the comments. – Daniel Möller Feb 25 '21 at 21:14
  • Cool... the error suddenly started happening again, same project, no changes in the interface or the external lib. – Daniel Möller Mar 05 '21 at 02:08

0 Answers0