Skip to content

Fix several issues with config merger#408

Merged
KirillOsenkov merged 2 commits intogluck:masterfrom
Alexx999:pr-config-merger
Jun 8, 2025
Merged

Fix several issues with config merger#408
KirillOsenkov merged 2 commits intogluck:masterfrom
Alexx999:pr-config-merger

Conversation

@Alexx999
Copy link
Copy Markdown
Contributor

@Alexx999 Alexx999 commented Jun 8, 2025

Hi,
You might remember me as owner of one of "more alive" forks back in the day.
I see that config merging got some attention in the past years which is great. But, fundamentally, I don't think that any non-schema-aware merging can be 100% successful.
This adds a little bit of awareness where it hurts me the most.

Trying the current implementation, I've encountered following issues:

  • multiple startup elements
    For us it's caused by different attributes
    If we run unmerged .exe only it's startup config is used -> the rest can be dropped when merging
    In theory, merging startup sections isn't so great either: e.g. primary .exe requires 4.8.1, merged-in 4.6.2, you end up with both 4.8.1 AND 4.6.2 which will cause problems
    So far, the fix is to at least drop multiple startups because that's bad merge output
  • all the assembly binding redirects from child assemblies go into the first element of the merged config
    Critical issue as it totally breaks redirections and causes merged .exe to crash
    Not merging is the answer
    But having stuff that cannot be merged based on name causes problems with the rest of the algorithm, so HashSet added to compensate
  • ilrepack crashes if child assembly config has comments
    Trivial fix, also fixes An error occurred while merging DLLs #401
  • if the assembly is merged in, the redirect entry for it is no longer needed
    Doesn't cause any real problems, so is cosmetic
    But annoying if you have large projects and trying to figure out why your merged exe has problem with redirects

- possible multiple startup elements
- all the assembly binding redirects from child assemblies go into the first <dependentAssembly> element
- ilrepack crashes if child assembly config has comments
- (cosmetic) if the assembly is merged in, the redirect entry for it is no longer needed
@KirillOsenkov
Copy link
Copy Markdown
Collaborator

to validate binding redirects, look into https://nuget.org/packages/checkbinarycompat

@Alexx999
Copy link
Copy Markdown
Contributor Author

Alexx999 commented Jun 8, 2025

In an ideal world everything should be fully processed and then semantically merged (i.e. if one redirect is -1.1.0.0 and the other is -1.2.0.0 the second is the right one to use).
But at least preventing schema violations is a good start - we have partial merges (some DLLs aren't merged in) and we do need redirects to keep working after the merge.
Having first dependentAssembly entry with multiple assemblyIdentity/bindingRedirect elements breaks the redirect system entirely. Merged .exe crashes in this case, so it's a critical issue.

Comment thread ILRepack/ConfigMerger.cs
{
var startups = root.Elements("startup");

foreach (var s in startups.Skip(1))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do you need a .ToArray() here? or does it work fine?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, you might be right.
My test case had 2 startup elements :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

wanna send a follow up or file a bug? or verify that it works fine

Comment thread ILRepack/ConfigMerger.cs
}
}

if (binding.Elements().Count() == 0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you can do !Any()

Copy link
Copy Markdown
Collaborator

@KirillOsenkov KirillOsenkov left a comment

Choose a reason for hiding this comment

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

👍

@KirillOsenkov KirillOsenkov merged commit 421197c into gluck:master Jun 8, 2025
1 check passed
@KirillOsenkov
Copy link
Copy Markdown
Collaborator

Thank you!

You fork was very helpful when reconciling multiple forks and PRs back into the main repo.

@KirillOsenkov
Copy link
Copy Markdown
Collaborator

Published 2.0.44

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.

An error occurred while merging DLLs

2 participants