Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null reference error on ResolveAssemblyReference #6049

Merged
merged 1 commit into from
Jan 26, 2021

Conversation

sfoslund
Copy link
Member

Context

Null reference error when ReferenceVersions are not set, introduced in #5990

Testing

Bug repros with dotnet/sdk#15430. These changes were tested with that PR and fix the issue.

@@ -1024,8 +1024,8 @@ List<Exception> generalResolutionExceptions
{
{ "logMessage", output },
{ "logMessageDetails", details },
{ "victorVersionNumber", victor.ReferenceVersion.ToString() },
{ "victimVersionNumber", conflictCandidate.ReferenceVersion.ToString() }
{ "victorVersionNumber", victor.ReferenceVersion?.ToString() },
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to pass an empty string rather than null if ReferenceVersion is null?

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't seem to effect the outcome, does it? Either way there isn't a value for the metadata on this item.

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't sure how it would ultimately was used, so I looked into it. Looks like it null checks anyway. LGTM

            /// <summary>
            /// Returns the escaped value of the requested metadata name.
            /// </summary>
            string ITaskItem2.GetMetadataValueEscaped(string metadataName)
            {
                ErrorUtilities.VerifyThrowArgumentNull(metadataName, nameof(metadataName));

                string metadataValue = null;

                if (FileUtilities.ItemSpecModifiers.IsDerivableItemSpecModifier(metadataName))
                {
                    // FileUtilities.GetItemSpecModifier is expecting escaped data, which we assume we already are.
                    // Passing in a null for currentDirectory indicates we are already in the correct current directory
                    metadataValue = FileUtilities.ItemSpecModifiers.GetItemSpecModifier(null, _escapedItemSpec, _escapedDefiningProject, metadataName, ref _fullPath);
                }
                else if (_customEscapedMetadata != null)
                {
                    _customEscapedMetadata.TryGetValue(metadataName, out metadataValue);
                }

                return metadataValue ?? String.Empty;
            }

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused—what does this code have to do with this PR?

Copy link
Member

@benvillalobos benvillalobos left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1024,8 +1024,8 @@ List<Exception> generalResolutionExceptions
{
{ "logMessage", output },
{ "logMessageDetails", details },
{ "victorVersionNumber", victor.ReferenceVersion.ToString() },
{ "victimVersionNumber", conflictCandidate.ReferenceVersion.ToString() }
{ "victorVersionNumber", victor.ReferenceVersion?.ToString() },
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't sure how it would ultimately was used, so I looked into it. Looks like it null checks anyway. LGTM

            /// <summary>
            /// Returns the escaped value of the requested metadata name.
            /// </summary>
            string ITaskItem2.GetMetadataValueEscaped(string metadataName)
            {
                ErrorUtilities.VerifyThrowArgumentNull(metadataName, nameof(metadataName));

                string metadataValue = null;

                if (FileUtilities.ItemSpecModifiers.IsDerivableItemSpecModifier(metadataName))
                {
                    // FileUtilities.GetItemSpecModifier is expecting escaped data, which we assume we already are.
                    // Passing in a null for currentDirectory indicates we are already in the correct current directory
                    metadataValue = FileUtilities.ItemSpecModifiers.GetItemSpecModifier(null, _escapedItemSpec, _escapedDefiningProject, metadataName, ref _fullPath);
                }
                else if (_customEscapedMetadata != null)
                {
                    _customEscapedMetadata.TryGetValue(metadataName, out metadataValue);
                }

                return metadataValue ?? String.Empty;
            }

@sfoslund
Copy link
Member Author

Thanks @Forgind @benvillalobos! I have a SDK PR depending on this that I'm hoping to get in by the end of the week so if you can merge this whenever your builds are working that would be great, thanks!

Copy link
Contributor

@cdmihai cdmihai left a comment

Choose a reason for hiding this comment

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

Worth adding a test for this, that would have caught the exception?

@sfoslund
Copy link
Member Author

sfoslund commented Jan 21, 2021

Worth adding a test for this, that would have caught the exception?

I don't have a deep understanding of RAR so I'm not sure how I would write a test for this within your infrastructure. However, the issue is repro'ed in several SDK tests now that we are enabling OutputUnresolvedAssemblyConflicts, so there is test coverage downstream.

If anyone wants to take a deeper look into how this happens, I've provided Nathan a binlog with the error.

@cdmihai
Copy link
Contributor

cdmihai commented Jan 21, 2021

However, the issue is repro'ed in several SDK tests now that we are enabling OutputUnresolvedAssemblyConflicts, so there is test coverage downstream.

Since RAR is a pain to think about, downstream coverage sounds good enough to me :)

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Jan 22, 2021
@marcpopMSFT marcpopMSFT changed the base branch from master to vs16.9 January 26, 2021 18:51
@marcpopMSFT marcpopMSFT merged commit 9153169 into dotnet:vs16.9 Jan 26, 2021
@sfoslund sfoslund deleted the RARNullRef branch January 26, 2021 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants