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

ApiInformation.IsPropertyPresent throws in an unpackaged app #2382

Closed
eerhardt opened this issue Apr 8, 2022 · 6 comments · Fixed by #1649
Closed

ApiInformation.IsPropertyPresent throws in an unpackaged app #2382

eerhardt opened this issue Apr 8, 2022 · 6 comments · Fixed by #1649
Assignees
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Apr 8, 2022

Describe the bug

When I call ApiInformation.IsPropertyPresent("Microsoft.UI.Xaml.Media.Imaging.BitmapImage", "IsAnimatedBitmap") in an unpackaged app it is throwing an exception:

Steps to reproduce the bug

  1. Create new “Blank App, Packaged (WinUI 3 in Desktop)” project.
  2. Edit the .csproj to add:
  <PropertyGroup>
    <WindowsPackageType>None</WindowsPackageType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.2" />
  </ItemGroup>
  1. Change the MainWindow.xaml.cs to have myButton_Click method as:
private void myButton_Click(object sender, RoutedEventArgs e)
{
    myButton.Content = ApiInformation.IsPropertyPresent("Microsoft.UI.Xaml.Media.Imaging.BitmapImage", "IsAnimatedBitmap");
}
  1. Build the app for Release, x64.
  2. run the .exe in the bin\x64\Release\net6.0-windows10.0.19041.0\win10-x64 folder
  3. Click the button

Expected behavior

The app shouldn't crash because ApiInformation.IsPropertyPresent should either return true or false and not throw an exception.

Actual behavior

System.InvalidOperationException
  HResult=0x80131509
  Message=Exception of type 'System.InvalidOperationException' was thrown.
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr) in D:\a\1\s\src\WinRT.Runtime\ExceptionHelpers.cs:line 82
 	WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR.__Throw|20_0(int hr) Line 82	C#
>	WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR(int hr) Line 85	C#
 	Microsoft.Windows.SDK.NET.dll!ABI.Windows.Foundation.Metadata.IApiInformationStaticsMethods.IsPropertyPresent(WinRT.IObjectReference _obj, string typeName, string propertyName) Line 493	C#
 	Microsoft.Windows.SDK.NET.dll!Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent(string typeName, string propertyName) Line 88	C#
 	App9.dll!App9.MainWindow.myButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) Line 34	C#
 	Microsoft.WinUI.dll!WinRT._EventSource_global__Microsoft_UI_Xaml_RoutedEventHandler.EventState.GetEventInvoke.AnonymousMethod__1_0(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) Line 7875	C#
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke.AnonymousMethod__0(Microsoft.UI.Xaml.RoutedEventHandler invoke) Line 43206	C#
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(System.IntPtr thisPtr, System.IntPtr sender, System.IntPtr e) Line 43215	C#

Screenshots

No response

NuGet package version

1.0.2

Packaging type

Unpackaged

Windows version

Windows 10 version 21H1 (19043, May 2021 Update)

IDE

Visual Studio 2022-preview

Additional context

cc @mattleibow

@eerhardt
Copy link
Member Author

An exception also occurs for ApiInformation.IsMethodPresent in an unpackaged app.

eerhardt added a commit to eerhardt/maui that referenced this issue Apr 11, 2022
Due to microsoft/WindowsAppSDK#2382, ApiInformation IsPropertyPresent and IsMethodPresent throw in unpackaged apps. Working around this problem by assuming BitmapImages support animation in unpackaged apps.

Fix dotnet#5927
eerhardt added a commit to eerhardt/maui that referenced this issue Apr 11, 2022
Due to microsoft/WindowsAppSDK#2382, ApiInformation IsPropertyPresent and IsMethodPresent throw in unpackaged apps. Working around this problem by assuming BitmapImages support animation in unpackaged apps.

Fix dotnet#5927
@jonwis
Copy link
Member

jonwis commented Apr 12, 2022

@DefaultRyan or @DrusTheAxe can you look into this? Unpackaged apps should still be causing the bootstrapper to load, which should be putting the right metadata into the package graph for the RoGetMetadata implementations behind this API.

@jonwis jonwis added the bug Something isn't working label Apr 12, 2022
@riverar
Copy link
Contributor

riverar commented Apr 12, 2022

Useful tidbit: This only repros on Windows 10. Not Windows 11 (22593 at least).

And is documented as a known issue: microsoft/microsoft-ui-xaml#6325

@DrusTheAxe
Copy link
Member

There's an issue in UndockedRegFreeWinRT not retrieving dynamic package graph entries in metadata lookup. This affects ApiInformation's use of WinRT metadata. I'm working on a fix.

36717508: UndockedRegFreeWinRT's Metadata lookup calls GetCurrentPackageInfo w/o PACKAGE_FILTER_DYNAMIC

@DrusTheAxe
Copy link
Member

This only repros on Windows 10. Not Windows 11 (22593 at least)

That is interesting. I'm not sure why. Thanks for the pointer, will investigate

mattleibow pushed a commit to dotnet/maui that referenced this issue Apr 13, 2022
* Maui Windows unpackaged app fails to start

Due to microsoft/WindowsAppSDK#2382, ApiInformation IsPropertyPresent and IsMethodPresent throw in unpackaged apps. Working around this problem by assuming BitmapImages support animation in unpackaged apps.

Fix #5927

* Remove calls to ApiInformation for BitmapImage since these APIs exist in Maui's minimum Windows version.
@ghost ghost added the Status: Fixed label May 19, 2022
@DrusTheAxe DrusTheAxe modified the milestones: 1.1, 1.2 May 20, 2022
@DrusTheAxe
Copy link
Member

This is fixed in main for 1.2
It's also up for 1.1-servicing

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

Successfully merging a pull request may close this issue.

5 participants