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

Setting FontFamily to null triggers a NullReferenceException #15287

Closed
MB-GA opened this issue Apr 9, 2024 · 3 comments
Closed

Setting FontFamily to null triggers a NullReferenceException #15287

MB-GA opened this issue Apr 9, 2024 · 3 comments

Comments

@MB-GA
Copy link

MB-GA commented Apr 9, 2024

Describe the bug

If the FontFamily field on an element is set to null, either directly by setting {x:Null} or indirectly via a binding, a NullReferenceException is raised internally once the element is evaluated. This will then crash the application as it never handles the exception.

To Reproduce

Add this element to a View: <TextBlock Text="hello" FontFamily="{x:Null}"/>

You can also bind it from a ViewModel and setting it to null from there:

View: <TextBlock Text="hello" FontFamily="{Binding Field}"/>
ViewModel: public FontFamily? Field => null;

Expected behavior

No response

Avalonia version

11.0.10

OS

Windows

Additional context

No response

@MB-GA MB-GA added the bug label Apr 9, 2024
@timunie
Copy link
Contributor

timunie commented Apr 9, 2024

what is the use-case here?

@MB-GA
Copy link
Author

MB-GA commented Apr 9, 2024

what is the use-case here?

None in particular: we're migrating from WPF, and in the process of this we ran into this bug. I'm only really reporting it to raise awareness of it since it can be hard to track down the source, as the exception occurs internally in Avalonia. IMO it should at least give information of where you're passing null in the view so you can figure out where the mistake is made.

@Symbai
Copy link
Contributor

Symbai commented Oct 15, 2024

@timunie This issue is already fixed. The PR author has just forgot to add this issue, instead he took his own issue number which was commented as a duplicate of this one: #15896

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants