Failed to build preview cannot find resource located in Settings.Designer.cs

Hi I'm facing this issue with xaml preview:

JetBrains.ReSharper.Features.XamlRendererExternal.WPF.WpfPreview+WpfPreviewCreationException: Failed to build preview ---> System.Xaml.XamlObjectWriterException: 'La valeur fournie sur 'System.Windows.StaticResourceExtension' a levé une exception.' numéro de ligne '9' et position de ligne '5'. ---> System.Exception: Impossible de trouver la ressource nommée'CustomFontSize'. Les noms de ressources respectent la casse.
à System.Windows.StaticResourceExtension.ProvideValueInternal(IServiceProvider serviceProvider, Boolean allowDeferredReference)
à System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)
à MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
--- Fin de la trace de la pile d'exception interne ---
à MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
à System.Xaml.XamlObjectWriter.Logic_ProvideValue(ObjectWriterContext ctx)
à System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)
à System.Xaml.XamlObjectWriter.WriteEndObject()
à System.Xaml.XamlObjectWriter.Dispose(Boolean disposing)
à System.Xaml.XamlWriter.System.IDisposable.Dispose()
à JetBrains.ReSharper.Features.XamlRendererExternal.WPF.PreviewXamlWriter`1.Dispose(Boolean disposing)
à System.Xaml.XamlWriter.System.IDisposable.Dispose()
à JetBrains.ReSharper.Features.XamlRendererExternal.WPF.WpfPreview.Create(String xaml, FileSystemPath assembliesRoot, FileSystemPath primaryAssemblyPath, IDictionary`2 aliasToAssembliesMap)
--- Fin de la trace de la pile d'exception interne ---
à JetBrains.ReSharper.Features.XamlRendererExternal.WPF.WpfPreview.Create(String xaml, FileSystemPath assembliesRoot, FileSystemPath primaryAssemblyPath, IDictionary`2 aliasToAssembliesMap)
à JetBrains.ReSharper.Features.XamlRendererExternal.XamlPreviewSessionProcessor.<Initialize>g__OnXamlMarkupUpdate|7_0(XamlMarkup markup)

 

The CustomFontSize is setted in Settings.Designer.cs, note that it's working well on Visual Studio

This is the xaml part where is located the usage of value:

<Window x:Class="SolutionWPF.Shared.Windows.MessageWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:controls="clr-namespace:SolutionWPF.Shared.Controls"
UseLayoutRounding="True"
TextElement.FontWeight="Regular"
TextElement.FontSize="{StaticResource CustomFontSize}"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="White"
FontFamily="{StaticResource CustomFontFamily}"
Title="MessageWindow" Height="350" Width="500" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Icon="/SolutionsA6CMO;component/Shared/Images/icon.ico" SizeToContent="Height" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Closing="Window_Closing">

How can I resolve this error?

0
3 comments

Hello Emmanuel, thank you for the description of the issue, but unfortunately I struggle to get the repro for it. Would it be possible to share sample project that we could use? And please specify Rider version you are using. Thank you in advance!

0

Hi, I finally could figure out by changing the xaml path to the CustomFontSize StaticResource. This value is located in the Project properties class Settings.Designer.cs file.

So, by adding an xmlns reference to that properties and then modifying the binding path to the resource, the errors disappeared:

<Window x:Class="SolutionWPF.Shared.Windows.MessageWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:controls="clr-namespace:SolutionWPF.Shared.Controls"
xmlns:settings="clr-namespace:SolutionWPF.Properties"
UseLayoutRounding="True"
TextElement.FontWeight="Regular"
TextElement.FontSize="{Binding Source={x:Static settings:Settings.Default}, Path=CustomFontSize}"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="White"
FontFamily="{Binding Source={x:Static settings:Settings.Default}, Path=CustomFontFamily}"
Title="MessageWindow" Height="350" Width="500" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Icon="/SolutionsA6CMO;component/Shared/Images/icon.ico" SizeToContent="Height" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Closing="Window_Closing">

Note that this problem does not occurs in Visual Studio 2019

0

Thank you for the reply. I tried that and have not faced the same exception, only "Error occurred while setting property TextElement.FontSize with message "Failed to set Static Resource with key: "CustomFontSize"", but the same I see in VS: 

While specifying it with binding path fixes the issue. Maybe I have made something differently, so to be more precise I would appreciate you sharing a sample that we could test. I would also appreciate you providing the logs collected right after issue happens so we could take a closer look and also have information about your system, like what Rider version you are using.

0

Please sign in to leave a comment.