dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

[Windows] Device.Display.MainDisplayInfo throws ArgumentException #4373

Closed PedroCigaw closed 2 years ago

PedroCigaw commented 2 years ago

Description

After testing the fix for #4126 Trying to get the DeviceDisplay.MainDisplayInfo

Trying to get the DeviceDisplay.MainDisplayInfo throws DeviceDisplay.MainDisplayInfo' threw an exception of type 'System.ArgumentException' Data: {System.Collections.ListDictionaryInternal} HResult: -2147024809 HelpLink: null InnerException: null Message: "Source object type is not a projected type and does not inherit from a projected type. (Parameter 'value')" ParamName: "value" Source: "WinRT.Runtime" StackTrace: " at WinRT.CastExtensions.GetRefForObject(Object value)\r\n at WinRT.CastExtensions.As[TInterface](Object value)\r\n at WinRT.Interop.WindowNative.GetWindowHandle(Object target)\r\n at Microsoft.Maui.Essentials.Platform.get_CurrentWindowHandle()\r\n at Microsoft.Maui.Essentials.Platform.get_CurrentWindowId()\r\n at Microsoft.Maui.Essentials.Platform.get_CurrentAppWindow()\r\n at Microsoft.Maui.Essentials.DeviceDisplayImplementation.GetMainDisplayInfo()\r\n at Microsoft.Maui.Essentials.DeviceDisplay.get_MainDisplayInfo()" TargetSite: {WinRT.IObjectReference GetRefForObject(System.Object)}

After testing the fix for #4125 Calling DeviceDisplay.MainDisplayInfoChanged += DeviceDisplay_MainDisplayInfoChanged throws System.ArgumentException HResult=0x80070057 Message=Source object type is not a projected type and does not inherit from a projected type. Arg_ParamName_Name Source=WinRT.Runtime StackTrace: at WinRT.CastExtensions.GetRefForObject(Object value) at WinRT.CastExtensions.As[TInterface](Object value) at WinRT.Interop.WindowNative.GetWindowHandle(Object target) at Microsoft.Maui.Essentials.Platform.get_CurrentWindowHandle() at Microsoft.Maui.Essentials.Platform.get_CurrentWindowId() at Microsoft.Maui.Essentials.Platform.get_CurrentAppWindow() at Microsoft.Maui.Essentials.DeviceDisplayImplementation.GetMainDisplayInfo() at Microsoft.Maui.Essentials.DeviceDisplay.add_MainDisplayInfoChanged(EventHandler1 value) at Microsoft.Maui.Controls.Application.SendStart() at Microsoft.Maui.Controls.Window.Microsoft.Maui.IWindow.Created() at Microsoft.Maui.LifecycleEvents.AppHostBuilderExtensions.<>c.b__1_0(Window window) at Microsoft.Maui.Platform.ApplicationExtensions.<>c__DisplayClass1_0.b__1(OnWindowCreated del) at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[TDelegate](IServiceProvider services, Action1 action) at Microsoft.Maui.Platform.ApplicationExtensions.CreateNativeWindow(Application nativeApplication, IApplication application, OpenWindowRequest args) at Microsoft.Maui.Platform.ApplicationExtensions.CreateNativeWindow(Application nativeApplication, IApplication application, LaunchActivatedEventArgs args) at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args) at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args) at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args) `

Steps to Reproduce

Issue 1.

  1. Create Maui Project
  2. In Windows Platform call DeviceDisplay.MainDisplayInfo

Issue 2.

  1. Create Maui app
  2. In App.xaml.cs after MainPage is set
  3. Add event handler DeviceDisplay.MainDisplayInfoChanged += DeviceDisplay_MainDisplayInfoChanged
  4. Run on windows local machine

Version with bug

Preview 12 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Window SDK 10.0.19041.0

Did you find any workaround?

No response

Relevant log output

No response

kristinx0211 commented 2 years ago

verified repro on windows. repro sample: #4373.zip

mattleibow commented 2 years ago

This should be fixed in Preview 14. Please open another issue if there are still problems.