C# – How to merge assembly?

In my two previous blogs C# – How to read header of SWF file? and C# – How to play a .swf file? , I showed you how to work around to read the header of a swf file so that we can load it exactly. In my blogs you can see that we need a reference to an ocx control so that we can play a swf file. When adding this ocx control, two referenced dll will be automatically added into project. They are AxInterop.ShockwaveFlashObjects.dll and Interop.ShockwaveFlashObjects.dll. Shipping these two dlls will make my tool broken because I would like to convert a swf file to an exe. I would not like to convert one file to 3 files. Therefore I think about method to merge all assemblies into only one. So I can use either ILMerge (from Microsoft) or AssMer (from my site).


ILMerge takes a set of input assemblies and merges them into one target assembly. The first assembly in the list of input assemblies is the primary assembly. When the primary assembly is an executable, then the target assembly is created as an executable with the same entry point as the primary assembly. Also, if the primary assembly has a strong name, and a .snk file is provided, then the target assembly is re-signed with the specified key so that it also has a strong name.


And now I would like to introduce to you AssMer, a tool to merge your assemblies. As its name, you can merge only until now ONLY assemblies with each other. You can not merge an assembly with a native code file.This tool is based on source code of Mono.Merge.

You can choose any tool which you like. ILMerge is a console application. You can find its GUI at ILMerge GUI. The following code is a code snippet which I extract from my tool. You can see that after merging we must fix the reference too.

static void Process(MergeContext context)
AssemblyDefinition primary = AssemblyFactory.GetAssembly(context.Assemblies[0]);

for (int i = 1; i < context.Assemblies.Count; i++)
AssemblyDefinition asm = AssemblyFactory.GetAssembly(context.Assemblies[i]);
asm.Accept(new StructureMerger(context, primary, asm));

FixReflectionAfterMerge fix = new FixReflectionAfterMerge(context, primary, primary);

AssemblyFactory.SaveAssembly(primary, context.OutputPath);

1 comment

  1. Which tool is more reliable, ILMerge or AssMer? Also tried .Net Reactor 4 (fast) and {SA} but that’s commercial stuff.

Leave a comment

Your email address will not be published. Required fields are marked *