ILMerge DLL: Assembly not merged in correctly, still listed as an external reference

15,006

Solution 1

I had to use the /closed argument. According to the official docs:

Closed

When this is set before calling Merge, then the "transitive closure" of the input assemblies is computed and added to the list of input assemblies. An assembly is considered part of the transitive closure if it is referenced, either directly or indirectly, from one of the originally specified input assemblies and it has an external reference to one of the input assemblies, or one of the assemblies that has such a reference. Complicated, but that is life...

Solution 2

I got a similar error message when trying to publish a web app that merged all outputs to a single assembly:

An error occurred when merging assemblies: ILMerge.Merge: The target assembly lists itself as an external reference.

This happens if the assembly name you are merging to matches the assembly name of the web application under Properties > Application. Changing the output assembly name should fix it.

Solution 3

This is exactly @HughJeffner's answer as an image. It took me a while & some tries to replicate the instructions.

Locations of the fields that should NOT be identical.

Solution 4

I got this error and it pointed to the Microsoft.Xrm.Sdk reference which I was merging into the single dll. The problem was fixed when I set another reference, Microsoft.Xrm.Sdk.Deployment to merge into the dll as well. Funny thing is in a separate project I had the 1st reference merging and the 2nd deployment dll not merging & it did not complain at all.

Share:
15,006

Related videos on Youtube

Fiona - myaccessible.website
Author by

Fiona - myaccessible.website

I have a Pluralsight course on web accessibility: Making a Web Form Accessible Web accessibility is more straightforward than you'd think. This course starts with an inaccessible web form and steps through each of the changes necessary to make it accessible, including an introduction to testing with free screen reader software. About Me Director of Software Development at Xibis (web & app development). Blogging about web accessibility at myaccessible.website Please email me at [email protected] or find me on Twitter.

Updated on January 14, 2022

Comments

  • Fiona - myaccessible.website
    Fiona - myaccessible.website over 2 years

    In the build process for a .NET C# tool, I have been using ILMerge to merge the assemblies into a single exe.

    I added a new class library recently, and now the ILMerge is failing. I have remembered to tell it to merge in the new DLL!

    It is now giving me this error, which I don't really understand:

    ILMerge.Merge: The assembly 'DataObjects' was not merged in correctly. It is still listed as an external reference in the target assembly.

    All of the assembly references I have done using 'project' references, and it has not failed in the past.

    Can anyone explain this error for me, or suggest a workaround please?

    • Jason D
      Jason D over 14 years
      Does it tell you the source assembly? Or can you use .Net reflector to find that?
    • Fiona - myaccessible.website
      Fiona - myaccessible.website over 14 years
      It is literally just outputting the line above. A few of the assemblies that I am trying to merge reference the 'DataObjects' assembly, but this has been the case for quite a while, and it is only when adding a new assembly that references it that I am getting the above error.
    • loraderon
      loraderon over 14 years
      Did you find a solution to this problem?
    • Fiona - myaccessible.website
      Fiona - myaccessible.website over 14 years
      Yes, please see my answer - hope it helps!
  • saminpa
    saminpa almost 6 years
    To add a bit of context, adding the /closed switch to the ilmerge command may 'work' but the underlying problem is that there is one (or more) unmerged assembly that holds a direct reference to something you're trying to merge out of existence. You probably want to check if this was intentional and maybe add the assembly explicitly to the merge operation - or get rid of the reference if it wasn't, to avoid future confusion...
  • Smith
    Smith over 2 years
    is this vs2022?