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

Bug: Bad/Missing ContractVersionAttribute on Windows.System.User.GetDefault #1844

Open
AliveDevil opened this issue Oct 24, 2024 · 2 comments

Comments

@AliveDevil
Copy link

AliveDevil commented Oct 24, 2024

Description

On Windows.System.User.GetDefault method it's stated that this is supported on WinRT Build 20348, Build 22000, Build 22621, Build 26100 only.
This is represented in the Windows.winmd file as well:

[ComImport]
[Windows.Foundation.Metadata.Guid(1956871697u, 11957, 17543, 176, 213, 44, 103, 144, 224, 19, 233)]
[ExclusiveTo(typeof(User))]
[ContractVersion(typeof(UniversalApiContract), 720896u)]
internal interface IUserStatics2
{
	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	User GetDefault();
}

Assuming UniversalApiContract version 720896 is v12/10.0.20348.0.

This is a mismatch between the User-class and IUserStatics2 implemented interface:
User-class:

[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public static extern User GetDefault();

Must be correlated with IUserStatics2-interface (i.e. if IUserStatics2.GetDefault() is 10.0.20348.0 only, then User.GetDefault has the same restriction).

Steps To Reproduce

Repro: sdaujfg.zip

I expect the compiler to warn me on User.GetDefault() that this callsite is unavailable on TargetFrameworkMinVersion.

Expected Behavior

GetDefault should be annotated with SupportedOSVersion("10.0.20348.0"), as is annotated on the IUserStatics2-interface in Windows metadata.

Version Info

dotnet --info
.NET SDK:
 Version:           8.0.403
 Commit:            c64aa40a71
 Workload version:  8.0.400-manifests.e99c892e
 MSBuild version:   17.11.9+a69bbaaf5
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetFrameworkMinVersion>10.0.0.17763.0</TargetFrameworkMinVersion>

Additional Context

No response

@dongle-the-gadget
Copy link
Contributor

I don’t think we already have this for older frameworks. In addition, for system WinRT classes, version checking is discouraged to feature checking, which is much harder to guard.

@AliveDevil
Copy link
Author

Fair, nevertheless, there is missing API contract information on User.GetDefault.

@AliveDevil AliveDevil changed the title Bug: Bad/Missing SupportOSVersion on Windows.System.User.GetDefault Bug: Bad/Missing ContractVersionAttribute on Windows.System.User.GetDefault Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants