runtime: Some incorrect NRT annotations in System.CodeDom
Description
Looks like System.CodeDom 7.0.0 enabled or updated NRT annotations and now we get build errors:
CodePrimitiveExpression.ctor(object)should beCodePrimitiveExpression.ctor(object?), testobject CodePrimitiveExpression.Valueshould beobject? CodePrimitiveExpression.Value, test- set of
Executor. ExecWaitWithCapturemethods withref stringparameters which should beref string?, test
Could be more, but that’s all we encountered during build of our code. I see tests already check for null values so it is possible to use NRT warnings from test code to detect more issues in this area.
Reproduction Steps
see referenced existing tests that test affected APIs with null
Expected behavior
No NRT errors
Actual behavior
CS8601, CS8604 errors on build
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (26 by maintainers)
Commits related to this issue
- Suppress nullable warnings in Serialization.Schema Now that Schema compiles against the source assembly of System.CodeDom, it receives nullability errors. I'm suppressing them manually for now but am... — committed to ViktorHofer/runtime by ViktorHofer 2 years ago
- Cleanup GenFacades logic and don't bind against non-shipping contract assemblies (#78703) * Clean-up the ApiCompat and GenAPI logic * Fix System.DirectoryServices.AccountManagement build System... — committed to dotnet/runtime by ViktorHofer 2 years ago
- Don't bind against non-shipping contract assemblies Manual backport of c8503d39053f9e0d94716a23c406b66f126ca259 Fixes https://github.com/dotnet/runtime/issues/77988 Unblocks https://github.com/dotnet... — committed to ViktorHofer/runtime by ViktorHofer 2 years ago
- Don't bind against non-shipping contract assemblies (#78730) Manual backport of c8503d39053f9e0d94716a23c406b66f126ca259 Fixes https://github.com/dotnet/runtime/issues/77988 Unblocks https://github... — committed to dotnet/runtime by ViktorHofer 2 years ago
There’s a 0% chance that the others are all fine.
All of these src projects use
<Nullable>annotations</Nullable>:<Nullable>annotations</Nullable>is dangerous… it says “my annotations are all correct; use them but don’t validate them”. That’s ok as a stopgap if the library won’t be directly referenced, but if it is, it means every reference type showing up as a return type is a potential false negative (because reference types become non-nullable and the compiler won’t warn you if you’re returning null) and every reference type showing up as a parameter is a potential false positive (because reference types become non-nullable so a consumer passing null will get warnings even if null is actually permitted by the API). It’s trivial to find cases where that happens, e.g.MemoryCache’s indexer returns null if the key isn’t in the cache, yet it’s annotated as returning the non-nullableobject, so there’s no warning when trying to dereference it even though it’ll null ref at run-time:I see four reasonable fixes here for .NET 8:
enableor explicitly havingannotations, and all of those would need to switch todisableas part of this.<Nullable>disable</Nullable>and make the code compile with liberal use of#pragma warning disable/restore.For v8, I don’t think there is enough time to fully annotate and review
System.CodeDom- RC1 snap is in 3 days. However, a fully annotated CodeDom would be welcome in v9.I assume that https://github.com/dotnet/runtime/pull/90393 is not needed for v8 when https://github.com/dotnet/runtime/pull/90401 is in.
That’d be very welcome, @halgab, thanks.
I’ve just started the work to fully annotate the System.CodeDom library. Would the team be interested in such a contribution?
Things like the Workflow compiler, SGEN, and other design time tools in VS load references with reflection - which loads assemblies for execution and fails with reference assemblies. Numerous reports about broken tools here are what led us to eventually just remove reference assemblies from packages. We also previously discussed with Roslyn/Nuget if it ever makes sense to make a public way to include reference assemblies in packages and the conclusion was no. IMO it doesn’t make sense to add back shipping reference assemblies here - they’ve been gone for multiple releases and the regressions we’d bring to design time experiences are worse than whatever nullable problems it might fix.
I agree with @stephentoub’s suggestion to go with option 4. That seems like the best way to get us back to what we shipped in 7.0 while still adding some incremental value.
It depends what we want the fix to be, even if a temporary fix for 8. A valid option is adding back a reference assembly. It’s not the only option, obviously.