Skip to content

[Group 1] Enable nullable annotations for Microsoft.Extensions.DependencyModel#57445

Merged
eerhardt merged 23 commits intodotnet:mainfrom
maxkoshevoi:mk/43605-DependencyModel
Sep 2, 2021
Merged

[Group 1] Enable nullable annotations for Microsoft.Extensions.DependencyModel#57445
eerhardt merged 23 commits intodotnet:mainfrom
maxkoshevoi:mk/43605-DependencyModel

Conversation

@maxkoshevoi
Copy link
Contributor

@maxkoshevoi maxkoshevoi commented Aug 15, 2021

Related to #43605, #54012

Ready for review, but not for merge

Questions (look for ! in the PR):

  • GetNormalizedCodeBasePath.GetNormalizedCodeBasePath is not used on net5+ due to Assembly.CodeBase being obsolete. Is there some alternative to preserve previous behavior, or is it ok to leave it like this?
    Suppressed warning for now.
  • It is always assumed that reader.GetString() returns non-null value, but it can return null.
    Should be resolved in: Remove ! from Microsoft.Extensions.DependencyModel #58139
  • It is always assumed that DependencyContextJsonReader.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 ! from Microsoft.Extensions.DependencyModel #58139
  • In AppBaseCompilationAssemblyResolver.TryResolveAssemblyPaths Path.GetDirectoryName(sharedPath) might return null, but this is not handled.
    Added Debug.Assert.

@ghost ghost added community-contribution Indicates that the PR has been added by a community member area-DependencyModel new-api-needs-documentation labels Aug 15, 2021
@ghost
Copy link

ghost commented Aug 15, 2021

Note regarding the new-api-needs-documentation label:

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.

@ghost
Copy link

ghost commented Aug 15, 2021

Tagging subscribers to this area: @eerhardt
See info in area-owners.md if you want to be subscribed.

Issue Details

Related to #43605, #54012

Ready for review, but not for merge

Questions (look for ! in the PR):

  • It is always assumed that reader.GetString() returns non-null value, but it can return null. Suppressed all errors with ! for now.
  • It is always assumed that DependencyContextJsonReader.Pool(str) returns non-null value, but it only does that for non-null when argument. Suppressed all errors with ! for now.
  • In AppBaseCompilationAssemblyResolver.TryResolveAssemblyPaths Path.GetDirectoryName(sharedPath) might return null, but this is not handled. Suppressed error with ! for now.
Author: maxkoshevoi
Assignees: -
Labels:

area-DependencyModel, new-api-needs-documentation, community-contribution

Milestone: -

string depsJsonFile = Path.ChangeExtension(assemblyLocation, DepsJsonExtension);
bool depsJsonFileExists = _fileSystem.File.Exists(depsJsonFile);

#if !NET5_0_OR_GREATER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we making this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assembly.CodeBase is deprecated in .net5+: #31127

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@maryamariyan maryamariyan added this to the 7.0.0 milestone Aug 17, 2021
while (reader.Read() && reader.IsTokenTypeProperty())
{
targets.Add(ReadTarget(ref reader, reader.GetString()));
targets.Add(ReadTarget(ref reader, reader.GetString()!));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this ! is lying that this can't be null. We should make the ReadTarget method accept string? targetName.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment for ReadTargetLibrary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added Debug.Assert here just in case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returned ! and created an issue #58139

string depsJsonFile = Path.ChangeExtension(assemblyLocation, DepsJsonExtension);
bool depsJsonFileExists = _fileSystem.File.Exists(depsJsonFile);

#if !NET5_0_OR_GREATER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

maxkoshevoi and others added 5 commits August 26, 2021 10:27
* Don't throw for null assemblies in TryResolveAssemblyPaths
* Fix up ref source
* Fix RuntimeLibrary constructor overloads
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-DependencyModel community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants