A lot of times when we are developing plug-ins and workflows, we are in need of adding multiple assemblies (.dll) into our main solution. The current scenario that we experienced is that we used itextsharp.dll assembly to edit the PDF Forms from within our plug-in and for that we have to merge the itextsharp.dll with our plug-in assembly.
The external itextsharp.dll file contained the special features which was the most important part of our solution.
We usually use ILMerge to merge these assemblies and ILMerge has made it successful to an extent, but sometimes we are stuck and our assemblies are not merged or in many cases it so happens that after the assemblies are merged and when we try to execute the workflows/plug-ins, we get an exception as “System.TypeLoad exception”.
In the latter condition, we have a merged assembly yet we are unsuccessful in implementing our logic. Even after spending hours on Google, we fail to come to any concrete solution and simply think what to do next.
So here is the solution, we just need to use our command prompt and write a simple command to get this working. The command is as follows:
“C:\Program Files\Microsoft\ILMerge\ILMerge.exe” /keyfile:”E:\XXXX \SigningFile.snk” /ndebug /targetplatform:4.0, “C:\Program Files\Reference assemblies\Microsoft\Framework\.NETFramework\v4.0″ /out:”E:\XXXX.dll” “E:\XXX.CRM.Plugin.dll” “E:\itextsharp.dll”
|“C:\Program Files\Microsoft\ILMerge\ILMerge.exe”||Path to your ILMerge dll.|
|/keyfile:”E:\XXXX \SigningFile.snk”||Path of your sign file.|
|/ndebug||ILMerge creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies.
Use this command if you do not want to create the .pdb file.
|/targetplatform:4.0, “C:\Program Files\Reference assemblies\Microsoft\Framework\.NETFramework\v4.0”||Path of your .Net 4.0 framework dll.|
|/out:”E:\XXXX.dll”||Path of your final dll.|
|“E:\XXX.CRM.Plugin.dll”||Path of your plugin/ workflow assembly.|
|“E:\itextsharp.dll”||Path of your additional assembly.|
Now, you might ask that why do we take the trouble of using command prompt instead of ILMerge UI?
The reason to use command prompt is that the target framework used in the ILMerge UI is 4.0.30319 whereas the expected target framework is 4.0 and hence we receive the Sysytem.TypeLoad exception whenever we execute our plug-in/workflow.
The above command is very useful for merging the different assemblies required by our solution and hence it proves to be helpful in implementing our logic.
Hope this helps.