Fix argument null exception when updating assembly references with no public key token #10568
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
Fix #10549.
See #10549 (comment) for context.
When a .NET Framework project contains an assembly reference that does not have "PublicKeyToken" specified, e.g.
The update will fail when updating assembly binding redirects in
app.config
/web.config
, e.g.From my [limited] understanding, the issue appears to be caused by a bug in the NuGet.Core v2 package.
The issue happens because when parsing assembly bindings, "PublicKeyToken" is optional and can be null. However, when writing assembly bindings to config, "PublicKeyToken" is assumed to be non-null, which causes the
ArgumentNullException
.This issue has been fixed in NuGet.Client (v3+) by adding extra null checks, but NuGetUpdater cannot update to this version without considerable rework.
The change proposed here makes "PublicKeyToken" required and treats
null
and the string literal"null"
as the same thing during comparisons. When parsing assembly bindings, the token will default to"null"
if not specified.The same fix was also applied to the "Culture" property, which appears to also be affected by this issue (must be non-null). It defaults to "neutral" if not specified.
Anything you want to highlight for special attention from reviewers?
If there is an easy way to remove NuGet.Core v2 and instead use NuGet.Client v6.x, that is probably the better way to fix this issue. I ran in to a lot of errors attempting to do this, but might not be doing it right.
How will you know you've accomplished your goal?
Updates to NuGet projects containing assembly references with no public key token complete without errors.
This can be tested with:
Checklist