-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Nullability annotations in XElement constructor #43416
Comments
Tagging subscribers to this area: @buyaa-n, @krwq, @jeffhandley |
Here's the bar we're using for whether or not to take nullable annotation fixes in 5.0:
Reviewing this issue, it meets that bar.
@krwq if you agree with this fix, I would support taking it to tactics for a 5.0 GA port this week. |
The XElement constructor that accepts an array of objects is very useful for building documents, specially for conditionally adding xml nodes to a parent node. If the element is null, nothing is added to the XElement. Looking forward for having this solved! var ele = new XElement("FlightRequest",
new XElement("From", "MAD"),
new XElement("To", "SFO"),
// this line gives warning CS8604
!string.IsNullOrEmpty(carrier) ? new XElement("Carrier", carrier) : null
); |
cc: @jozkee who annotated XLinq |
quickly looking at the code I think the code should be fine with accepting null as array elements so if you find this scenario common I'm fine with this change |
Should we expand this to other signatures containing https://source.dot.net/#System.Private.Xml.Linq/System/Xml/Linq/XElement.cs,986 There may be more cases. |
yes, we should back track and find all instances and be consistent across APIs |
As noted on #43717, this fix will target 6.0 and won't meet the bar for getting merged into 5.0 at this point. Thank you again for reporting it, @olmobrutall; I'm sorry for the inconvenience that will exist here. |
It's a pity... not for me, I've already updated to .Net 5 preview, but for any other project using Linq to Xml with NRT. But just to have an idea of the impact, check out this commit signumsoftware/extensions@cdba46f and search for Maybe this example can be of use to escalate it and get into .Net 5. Nobody wants a .Net 5.1 just for one |
I appreciate the extra data, @olmobrutall. I double-checked and got confirmation that this doesn't meet our 5.0 bar at this stage. I recognize the frustration this will cause for you and many others, but we won't be able to fix it until 6.0. We expect there will be other fixes to nullable annotations that we'll make in 6.0 too, which we'll be accumulating in a single document. We anticipated that we would make mistakes in our annotations, and we're grateful that you reported this one as quickly as you did so that others will be able to discover the existing issue and know that they can apply a |
After downloading the latest .Net 5 SDK (Preview 2) I'm starting to update my code to it.
I'm using nullable reference types.
I think the nullability annotations could be improved in
runtime/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XElement.cs
Line 95 in 035b729
The text was updated successfully, but these errors were encountered: