Skip to content

DBusPlatformSettings: NullReferenceException occurs if there is no DBusHelper.DefaultConnection #21821

Description

@pos777

Describe the bug

The NullReferenceException occurs during Window creation

>	Avalonia.FreeDesktop.DBusPlatformSettings.TryGetThemeVariantAsync()
 	Avalonia.FreeDesktop.DBusPlatformSettings.TryGetInitialValuesAsync()
 	Avalonia.FreeDesktop.DBusPlatformSettings.OnRequestDefaultThemeVariant()
 	Avalonia.X11.X11Window.SetFrameThemeVariant(themeVariant)
 	Avalonia.Controls.TopLevel..ctor.AnonymousMethod__43_1(variant)
 	Avalonia.Controls.TopLevel.CreatePlatformImplBinding.__UpdatePlatformImpl|0()
 	Avalonia.Controls.TopLevel.CreatePlatformImplBinding<Avalonia.Styling.ThemeVariant>(property, onValue)
 	Avalonia.Controls.TopLevel.TopLevel(impl, dependencyResolver)
 	Avalonia.Controls.WindowBase.WindowBase(impl, dependencyResolver)
 	Avalonia.Controls.WindowBase.WindowBase(impl)
 	Avalonia.Controls.Window.Window(impl)
 	Avalonia.Controls.Window.Window()

private async Task<PlatformThemeVariant?> TryGetThemeVariantAsync()
{
try
{
var version = await _settings!.GetVersionAsync();

It happens if the DBusPlatformSettings._settings field is not initialized due to the absence of DBusHelper.DefaultConnection:

public DBusPlatformSettings()
{
if (DBusHelper.DefaultConnection is not { } conn)
return;
_settings = new Settings(conn, "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop");

To Reproduce

Tests in internal CI fail during migration to v12.1.0. Not sure how to reproduce this locally.

Expected behavior

No response

Avalonia version

12.1.0

OS

Linux

Additional context

Probably introduced in #16340

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions