[Group 1] Enable nullable annotations for Microsoft.Extensions.DependencyModel#57445
[Group 1] Enable nullable annotations for Microsoft.Extensions.DependencyModel#57445eerhardt merged 23 commits intodotnet:mainfrom
Microsoft.Extensions.DependencyModel#57445Conversation
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
Tagging subscribers to this area: @eerhardt Issue DetailsReady for review, but not for merge Questions (look for
|
src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextJsonReader.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextJsonReader.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextJsonReader.cs
Outdated
Show resolved
Hide resolved
| string depsJsonFile = Path.ChangeExtension(assemblyLocation, DepsJsonExtension); | ||
| bool depsJsonFileExists = _fileSystem.File.Exists(depsJsonFile); | ||
|
|
||
| #if !NET5_0_OR_GREATER |
There was a problem hiding this comment.
Why are we making this change?
There was a problem hiding this comment.
Assembly.CodeBase is deprecated in .net5+: #31127
There was a problem hiding this comment.
I don't think removing this code is a good idea for now. You should just suppress the Obsolete warning instead. Ex:
#pragma warning disable SYSLIB0012 // CodeBase is obsoleteThere was a problem hiding this comment.
Just suppressing the warning breaks CI:
Using member 'System.Reflection.Assembly.CodeBase' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app. This member throws an exception for assemblies embedded in a single-file app.
src/libraries/Microsoft.Extensions.DependencyModel/ref/Microsoft.Extensions.DependencyModel.cs
Outdated
Show resolved
Hide resolved
| while (reader.Read() && reader.IsTokenTypeProperty()) | ||
| { | ||
| targets.Add(ReadTarget(ref reader, reader.GetString())); | ||
| targets.Add(ReadTarget(ref reader, reader.GetString()!)); |
There was a problem hiding this comment.
I think this ! is lying that this can't be null. We should make the ReadTarget method accept string? targetName.
There was a problem hiding this comment.
Similar comment for ReadTargetLibrary
There was a problem hiding this comment.
Experimented with it and looks like targetName shouldn't be null, or code will NRE elsewhere:
- https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextJsonReader.cs#L195 (
IsRuntimeTargetwould crash ifNameis null) - https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextJsonReader.cs#L202 (
new TargetInfo(framework...)a bit later would crash ifframeworkis null) - https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextJsonReader.cs#L238 (
IsRuntimeTargetwould crash ifNameis null)
There was a problem hiding this comment.
I've added Debug.Assert here just in case
src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextWriter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/src/Utf8JsonReaderExtensions.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/src/Utf8JsonReaderExtensions.cs
Outdated
Show resolved
Hide resolved
# Conflicts: # src/libraries/Microsoft.Extensions.DependencyModel/src/Dependency.cs
...braries/Microsoft.Extensions.DependencyModel/src/Microsoft.Extensions.DependencyModel.csproj
Outdated
Show resolved
Hide resolved
...braries/Microsoft.Extensions.DependencyModel/ref/Microsoft.Extensions.DependencyModel.csproj
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/ref/Microsoft.Extensions.DependencyModel.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/src/RuntimeAssetGroup.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/ref/Microsoft.Extensions.DependencyModel.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/ref/Microsoft.Extensions.DependencyModel.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextWriter.cs
Outdated
Show resolved
Hide resolved
| string depsJsonFile = Path.ChangeExtension(assemblyLocation, DepsJsonExtension); | ||
| bool depsJsonFileExists = _fileSystem.File.Exists(depsJsonFile); | ||
|
|
||
| #if !NET5_0_OR_GREATER |
There was a problem hiding this comment.
I don't think removing this code is a good idea for now. You should just suppress the Obsolete warning instead. Ex:
#pragma warning disable SYSLIB0012 // CodeBase is obsolete
src/libraries/Microsoft.Extensions.DependencyModel/src/DependencyContextJsonReader.cs
Outdated
Show resolved
Hide resolved
TODO: Create an issue to remove !
* Don't throw for null assemblies in TryResolveAssemblyPaths * Fix up ref source * Fix RuntimeLibrary constructor overloads
eerhardt
left a comment
There was a problem hiding this comment.
Thank you again, @maxkoshevoi, for this work. This really helps!
I pushed a couple commits to this branch to get the build and unit tests passing. I also fixed a few nits and inconsistencies while I was working here.
I'll merge this once CI is green.
Related to #43605, #54012
Ready for review, but not for merge
Questions (look for
!in the PR):GetNormalizedCodeBasePath.GetNormalizedCodeBasePathis not used on net5+ due toAssembly.CodeBasebeing obsolete. Is there some alternative to preserve previous behavior, or is it ok to leave it like this?Suppressed warning for now.
reader.GetString()returns non-null value, but it can returnnull.Should be resolved in: Remove
!fromMicrosoft.Extensions.DependencyModel#58139DependencyContextJsonReader.Pool(str)returns non-null value, but it only does that for non-null when argument. Suppressed errors with!for now.Should be resolved in: Remove
!fromMicrosoft.Extensions.DependencyModel#58139AppBaseCompilationAssemblyResolver.TryResolveAssemblyPathsPath.GetDirectoryName(sharedPath)might returnnull, but this is not handled.Added
Debug.Assert.