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

Unexpected false Result When Using ApiInformation IsTypePresent with Custom Types #10098

Open
morning4coffe-dev opened this issue Oct 23, 2024 · 1 comment
Labels
area-CoreFramework Issues on fundamental components like UIElement, visibility, etc. bug Something isn't working

Comments

@morning4coffe-dev
Copy link

Describe the bug

When invoking ApiInformation.IsTypePresent on a custom type, it unexpectedly returns false, which seems like incorrect behavior. This issue occurs despite the type being defined and accessible within the application. For example, the method correctly identifies built-in types like Button, but it fails with custom types such as MainPage.

This suggests that ApiInformation.IsTypePresent may not be functioning as expected when handling custom types.

Steps to reproduce the bug

  1. Add a custom type:

    • Define some custom page or class, for example MainPage
  2. Use ApiInformation.IsTypePresent to check for types:

    • In the MainPage or another part of the project, call ApiInformation.IsTypePresent to check for both a built-in and a custom type.
    var buttonIsType = ApiInformation.IsTypePresent(typeof(Button).FullName);  // Should return true
    
    var mainpageIsType = ApiInformation.IsTypePresent(typeof(MainPage).FullName);  // Returns false (unexpected)
  3. Run the project:

    • Observe that ApiInformation.IsTypePresent returns true for built-in types like Button, but returns false for the custom MainPage type

Expected behavior

Both built-in and custom types should return true when passed to ApiInformation.IsTypePresent.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.6.1: 1.6.240923002

Windows version

Windows Insider Build (xxxxx)

Additional context

No response

@DarranRowe
Copy link

DarranRowe commented Oct 23, 2024

ApiInformation is a metadata operation. This means that the metadata has to be present.

Image

This is a C++ example, but in this case the .winmd file is next to the executable. The .winmd file is also named after the root namespace. So does the metadata file exist next to the executable? If it doesn't exist, does the result change if you include the metadata file?

Just in case you are wondering from these questions, yes I can see a problem. As you should see from the screenshot I posted, for C++, the output directory does contain the .winmd file. If the unpackaged version of the application is run, then for C++ then ApiInformation will return true to indicate that the type is present. However, when the application is packaged, the packaging process doesn't seem to copy this file.

Image

For C# projects, I noticed that it doesn't naturally create .winmd files. However, ProcessMonitor shows that ApiInformation only triggers a search for .winmd files.

Image

So in order to use ApiInformation, you would have to generate a .winmd file for your project. I have no idea if this is possible from the .NET metadata, since I am mainly a C++ developer. However, the documentation doesn't clearly document this requirement.

@karkarl karkarl added area-CoreFramework Issues on fundamental components like UIElement, visibility, etc. and removed needs-triage Issue needs to be triaged by the area owners labels Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CoreFramework Issues on fundamental components like UIElement, visibility, etc. bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants