Skip to content

Fix the assembly metadata extractor to use the filename instead of the full name - #3334

Merged
nkolev92 merged 4 commits into
devfrom
dev-nkolev92-fixAssemblyExtractor
Apr 23, 2020
Merged

nkolev92 merged 4 commits into
devfrom
dev-nkolev92-fixAssemblyExtractor

Conversation

@nkolev92

@nkolev92 nkolev92 commented Apr 8, 2020 •

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#4234
Regression: yes

  • Last working version: 3.4.x
  • How are we preventing it in future: Test

Fix

Details:
Use CreateInstanceFromAndUnwrap instead of CreateInstanceAndUnwrap to allow the assembly resolution to work when the exe is renamed.

Testing/Validation

Tests Added: Yes
Reason for not adding tests:
Validation: Manual, tests

@nkolev92
nkolev92 force-pushed the dev-nkolev92-fixAssemblyExtractor branch from 31f96f5 to 790b85e Compare April 10, 2020 22:08
private static T CreateInstance<T>(this AppDomain domain)
{
return (T)domain.CreateInstanceAndUnwrap(typeof(T).Assembly.FullName, typeof(T).FullName);
return (T)domain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof(T).FullName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add comments why choose the CreateInstanceFromAndUnwrap instead of CreateInstanceAndUnwrap.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because it works when an assembly is renamed? :)

There are tests covering this scenario, and I don't see this as a complex change that requires additional explanation.

My thought is adding a comment is too much, but can add it if we think it's necessary.

Comment thread build/vsts_build.yaml Resolved
private static T CreateInstance<T>(this AppDomain domain)
{
return (T)domain.CreateInstanceAndUnwrap(typeof(T).Assembly.FullName, typeof(T).FullName);
return (T)domain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof(T).FullName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given nuget.exe is ILMerged, it probably doesn't matter, but would keeping the typeof(T) be a bit safer, rather than Assembly.GetExecutingAssembly()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Technically yeah, if anyone ever moves these types around it would be safer, but there's a test to catch this.

If you care I can change it but I'd reallly hate to try to fight with CI because of a change like that :D

lmk, this merge is not time critical so we can go through the CI churn if necessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@zivkan Do you care about this or should I merge?

@nkolev92
nkolev92 requested a review from cristinamanum April 15, 2020 20:15
@nkolev92
nkolev92 merged commit ce8617f into dev Apr 23, 2020
@nkolev92
nkolev92 deleted the dev-nkolev92-fixAssemblyExtractor branch April 23, 2020 19:08
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.

NuGet.exe throws exception 'authors required' during pack of a csproj ignoring placeholders and assemblyinfo attributes if the assembly name is changed

3 participants