html-agility-pack icon indicating copy to clipboard operation
html-agility-pack copied to clipboard

Wrong compilation with nullability support

Open trejjam opened this issue 5 months ago • 3 comments

Hi, I have noticed that the target framework changed with the new version. That breaks the nullability annotations.

Image

The issue is that the used preprocessor directive is NET8_0. To prevent similar issues in the future, it should be at least NET8_0_OR_GREATER. https://github.com/zzzprojects/html-agility-pack/blob/8490ad1321e378582aec156668888511d3010b33/src/HtmlAgilityPack.Shared/HtmlNode.Xpath.cs#L41

And since nullable annotations have been available since c# 8, which came with Net Core 3 it might be a good idea to use NET5_0_OR_GREATER. In case someone will lower the target framework again. https://learn.microsoft.com/en-us/dotnet/standard/frameworks#preprocessor-symbols

I can make the PR that will fix the issue, if you like.

trejjam avatar Jul 22 '25 13:07 trejjam

  • 1.12.0 was a failure for those who use nullability in their projects.
  • 1.12.1 was a particular win, as it fixed most of the issues.
  • 1.12.2 feels like a step backward again.

SerhiyBalan avatar Jul 28 '25 08:07 SerhiyBalan

This PR should fix it.

https://github.com/zzzprojects/html-agility-pack/pull/598

StefH avatar Aug 14 '25 19:08 StefH

1.12.1 was a particular win, as it fixed most of the issues

One I bumped into a lot was with the HtmlAttributeCollection:

public HtmlAttribute this[string name]

As the getter returns null if the named attribute does not exist in the collection. Would love to see this updated.

JonSaffron avatar Aug 17 '25 08:08 JonSaffron