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

Crash when opening window at startup on Windows Server Core #15840

Closed
mojoe-playground opened this issue May 28, 2024 · 2 comments · Fixed by #15852
Closed

Crash when opening window at startup on Windows Server Core #15840

mojoe-playground opened this issue May 28, 2024 · 2 comments · Fixed by #15852
Labels
bug help-wanted A contribution from the community would be most welcome. os-windows

Comments

@mojoe-playground
Copy link
Contributor

mojoe-playground commented May 28, 2024

Describe the bug

Getting null reference exception at startup in Window constructor on Windows Server Core 2016. Based on call stack it could not initialialize TaskBarList, probably because Server Core does not have a task bar.

Same application runs using AvaloniaUI version 11.0.10.

To Reproduce

  1. Create a new avalonia app
  2. Run it in a Windows Server Core 2016 OS (probably any Server Core OS, but tested only with 2016)

Expected behavior

App not crashing at startup and main window shows

Avalonia version

11.1.0-beta2

OS

Windows

Additional context

Call stack:

System.NullReferenceException: Object reference not set to an instance of an object.
at Avalonia.Win32.Interop.TaskBarList.Init()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func'1 valueFactory)
at System.Threading.LazyInitializer.EnsureInitialized[T](T& target, Boolean& initialized, Object& syncLock, Func'1 valueFactory)
at Avalonia.Win32.Interop.TaskBarList.LazyInit()
at Avalonia.Win32.Interop.TaskBarList.SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, String description)
at Avalonia.Win32.WindowImpl.RefreshIcon()
at Avalonia.Win32.WindowImpl.SetIcon(IWindowIconImpl icon)
at Avalonia.Controls.Window.<.ctor>b__31_2(WindowIcon icon)
at Avalonia.Controls.TopLevel.<>c__DisplayClass72_0'1.g__UpdatePlatformImpl|0()
at Avalonia.Controls.TopLevel.CreatePlatformImplBinding[TValue](StyledProperty'1 property, Action'1 onValue)
at Avalonia.Controls.Window..ctor(IWindowImpl impl)
at Avalonia.Controls.Window..ctor()
at Project1.MainWindow..ctor() in D:\Development\Repos\Project1\Project1\MainWindow.axaml.cs:line 7
at Project1.App.OnFrameworkInitializationCompleted() in D:\Development\Repos\Project1\Project1\App.axaml.cs:line 18
at Avalonia.AppBuilder.SetupUnsafe()
at Avalonia.AppBuilder.Setup()
at Avalonia.AppBuilder.SetupWithLifetime(IApplicationLifetime lifetime)
at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action'1 lifetimeBuilder)
at Project1.Program.Main(String[] args) in D:\Development\Repos\Project1\Project1\Program.cs:line 21

@thevortexcloud
Copy link
Contributor

thevortexcloud commented May 29, 2024

Well Windows Core does not have a taskbar (or a traditional Windows desktop). So it's not surprising it can't query the task bar info. I imagine it should just return a 0 ptr if it can't query the taskbar, as the code seems to already handle that.

public static unsafe void MarkFullscreen(IntPtr hwnd, bool fullscreen)
{
LazyInit();
if (s_taskBarList != IntPtr.Zero)
{

Although I can't say I am too familiar with what Avalonia does at this level.

@maxkatz6 maxkatz6 added help-wanted A contribution from the community would be most welcome. os-windows labels May 29, 2024
@maxkatz6
Copy link
Member

as the code seems to already handle that.

It's likely fails at this line

s_hrInitDelegate ??= Marshal.GetDelegateForFunctionPointer<HrInit>((*ptr)->HrInit);

As ptr is null (empty) there, as it seems.

Should be an easy fix for anybody who want to try and can test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A contribution from the community would be most welcome. os-windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants