Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use custom font in <Style> #2939

Closed
dszymon opened this issue Sep 7, 2019 · 4 comments
Closed

Unable to use custom font in <Style> #2939

dszymon opened this issue Sep 7, 2019 · 4 comments
Projects

Comments

@dszymon
Copy link

dszymon commented Sep 7, 2019

Following code

<Style Selector="Button">
    <Setter Property="FontFamily" Value="resm:someProj.Assets.SomeFont.ttf?assembly=resm:someProj#SomeFontName"/>
</Style>

throws an exception

Portable.Xaml.XamlObjectWriterException
  HResult=0x80131500
  Message=Set value of member '{clr-namespace:Avalonia.Styling;assembly=Avalonia.Styling}Setter.Value' threw an exception
  Source=Avalonia.Markup.Xaml
  StackTrace:
   at Portable.Xaml.XamlObjectWriterInternal.SetValue(XamlMember member, Object target, Object value)
   at Portable.Xaml.XamlObjectWriterInternal.SetValue(XamlMember member, Object value)
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteEndMember()
   at Portable.Xaml.XamlWriterInternalBase.WriteEndMember()
   at Portable.Xaml.XamlObjectWriter.WriteEndMember()
   at Portable.Xaml.XamlWriter.WriteNode(XamlReader reader)
   at Portable.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)
   at Portable.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.LoadFromReader(XamlReader reader, AvaloniaXamlContext context, IAmbientProvider parentAmbientProvider)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Stream stream, Assembly localAssembly, Object rootInstance, Uri uri)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Type type, Object rootInstance)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Object obj)
   at resm:someProj.Views.MainWindow.InitializeComponent() in C:\Users\x\Desktop\yr\Views\MainWindow.xaml.cs:line 77
   at resm:someProj.Views.MainWindow..ctor(MainWindowViewModel vm) in C:\Users\x\Desktop\y\Views\MainWindow.xaml.cs:line 28

Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.
@danwalmsley danwalmsley added this to To do in 0.9 Release via automation Sep 7, 2019
@danwalmsley
Copy link
Member

@kekekeks seen quite a few reports of this, something up in XamlIL?

@kekekeks
Copy link
Member

kekekeks commented Sep 7, 2019

@danwalmsley as you can clearly see, the exception is rethrown by the Portable.Xaml.

@jmacato
Copy link
Member

jmacato commented Sep 8, 2019

@danwalmsley @kekekeks this is only an issue for older releases i think. Had encountered the same error in Wasabi (zkSNACKs/WalletWasabi#2136) so i had to declare the font as a resource like so:

  <FontFamily x:Key="MonospacedFont">
        <x:Arguments>
          <x:String>Inconsolata</x:String>
          <x:Uri>resm:WalletWasabi.Gui.Assets.*.ttf?assembly=WalletWasabi.Gui</x:Uri>
        </x:Arguments>
   </FontFamily>

then reference the font with {StaticResource MonospacedFont}

@grokys
Copy link
Member

grokys commented Sep 9, 2019

Seems to be a duplicate of #2194, which should be fixed on master, so going to close this. Please let us know if it's still a problem on the latest nightly releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
0.9 Release
  
Done
Development

No branches or pull requests

5 participants