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

Question: C# Nullable Reference Types #5050

Closed
Marv51 opened this issue May 20, 2021 · 9 comments
Closed

Question: C# Nullable Reference Types #5050

Marv51 opened this issue May 20, 2021 · 9 comments
Labels
area-C#/WinRT area-External Not owned by the WinUI team, not actionable in this repository. feature proposal New feature proposal product-winui3 WinUI 3 issues team-Markup Issue for the Markup team

Comments

@Marv51
Copy link
Contributor

Marv51 commented May 20, 2021

Nullable Reference Types were introduced in C# 8 with .NET Core 3.0. This was never a topic of concern for UWP and WinUI because the .NET Native toolchain never got updated to C# 8.

Now that WinUI 3 is (at least on desktop) based on .NET 5, WinUI should add Nullability annotations to it's public API.

Annotations can be added incrementally, so WinUI could start by annotating some frequently used interfaces.

Is there a plan for this already in place?

I could not find any issue tracking this feature and no entry on the roadmap either.

Related issue for .NET 6: dotnet/runtime#43619
Related tracking issue in communit toolkit: CommunityToolkit/WindowsCommunityToolkit#3958

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label May 20, 2021
@JaiganeshKumaran
Copy link
Contributor

JaiganeshKumaran commented May 20, 2021

WinUI is a Windows Runtime component, not a .NET library and WinRT doesn't have the notion of a nullable reference types.

@Marv51
Copy link
Contributor Author

Marv51 commented May 20, 2021

@JaiganeshKumaran I was wondering that, but I guess CsWinRT could generate those annotations, could it not?

@Scottj1s Is that something CsWinRT has thought about? Would be that be even possible?

@huoyaoyuan
Copy link

CsWinRT follows the api in winmd. There must be such support in winmd first.

@Marv51
Copy link
Contributor Author

Marv51 commented May 20, 2021

Custom attributes, similar to SupportedOSPlatform, would be one possible way to go, wouldn't it?

@huoyaoyuan
Copy link

The CsWinRT needs information to correctly annotate the apis. If not reading from winmd, there must be somewhere else to tell it which apis are nullable.

@StephenLPeters
Copy link
Contributor

@Scottj1s FYI

@StephenLPeters StephenLPeters added area-External Not owned by the WinUI team, not actionable in this repository. and removed needs-triage Issue needs to be triaged by the area owners labels May 20, 2021
@contextfree
Copy link

contextfree commented May 24, 2021

There's actually a proposal to support non-nullable reference type annotations in the WinRT type system and projections here: microsoft/xlang#716 with an associated pull request to the WinRT documentation (which seems to have been abandoned for some reason): microsoft/xlang#708

This would be very helpful for Rust as well.

@Marv51
Copy link
Contributor Author

Marv51 commented Jul 19, 2023

Keep alive (re #8638)

@bpulliam bpulliam added the team-Markup Issue for the Markup team label Aug 8, 2023
@bpulliam bpulliam added feature proposal New feature proposal and removed question labels Oct 18, 2023
@Scottj1s
Copy link
Member

@Marv51 given the need to coordinate work in several areas (metadata attributes, WinUI application, midlrt.exe processing, cswinrt.exe processing), I don't see this coming together any time soon. I also don't think the original xlang proposal is practical. Given that nearly all WinRT APIs do not return null references (e.g., constructors would throw some other exception), it seems that the path of least resistance would be to assume NotNull by default and annotate exceptions to that (MaybeNull), and instrument cswinrt.exe to project accordingly (all reference parameters and returns are NotNull unless marked MaybeNull). In any case, I think a proposal needs to be outlined, and benefits described, before work proceeds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-C#/WinRT area-External Not owned by the WinUI team, not actionable in this repository. feature proposal New feature proposal product-winui3 WinUI 3 issues team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

7 participants