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

Update framework detection logic to not rely on throwing/catching NRE #3714

Merged
merged 2 commits into from
Jun 3, 2022

Conversation

Evangelink
Copy link
Member

Description

Update framework detection logic to not rely on throwing/catching NRE. When running some tests locally in Debug we had Debug.Assert failures, in CI/release the behavior was the same as before because assert are ignored.

@@ -32,7 +32,7 @@ internal AssemblyMetadataProvider(IFileHelper fileHelper)
}

/// <inheritdoc />
public FrameworkName GetFrameWork(string filePath)
public FrameworkName GetFrameworkName(string filePath)
Copy link
Member Author

Choose a reason for hiding this comment

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

Somehow unrelated but I got confused by the API name compared to its return type when fixing the auto-detection algorithm so I also fixed the name.

framework);
}
}
catch (Exception ex)
Copy link
Member Author

Choose a reason for hiding this comment

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

Try/catch was only catching NRE when finalFx is null which happens only when all sources provided are null. DetermineFrameworkName and Framework.FromString are having inner try/catch.

@@ -133,35 +133,24 @@ public Architecture AutoDetectArchitecture(IList<string?>? sources, Architecture
public Framework AutoDetectFramework(IList<string?>? sources, out IDictionary<string, Framework> sourceToFrameworkMap)
{
sourceToFrameworkMap = new Dictionary<string, Framework>();
Framework framework = Framework.DefaultFramework;

if (sources == null || sources.Count == 0)
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not filtering null sources here because the simplest solution is to actually return Framework instead of FrameworkName on DetermineFramework. This way I can solve the "problem" of instances equality.

return framework;
}

private FrameworkName? DetermineFrameworkName(IEnumerable<string?> sources, out IDictionary<string, Framework> sourceToFrameworkMap, out bool conflictInFxIdentifier)
private Framework DetermineFramework(IEnumerable<string?> sources, out IDictionary<string, Framework> sourceToFrameworkMap, out bool conflictInFxIdentifier)
Copy link
Member Author

Choose a reason for hiding this comment

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

Potentially we could move this as local function of AutoDetetFramework.

@Evangelink Evangelink changed the title Update framework detection logic to not rely on throwing/catching NRE [After #3716] Update framework detection logic to not rely on throwing/catching NRE Jun 2, 2022
@Evangelink Evangelink changed the title [After #3716] Update framework detection logic to not rely on throwing/catching NRE Update framework detection logic to not rely on throwing/catching NRE Jun 2, 2022
@Evangelink Evangelink enabled auto-merge (squash) June 2, 2022 18:47
@Evangelink Evangelink merged commit 16cde7f into microsoft:main Jun 3, 2022
@Evangelink Evangelink deleted the prevent-expected-NRE branch June 6, 2022 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants