Search code examples
.netvisual-studioilmerge

Unable to load DLL mscorsn.dll with ILMerge


I am trying to compile a project that uses ILMerge to combine multiple DLLs together and then sign them for deployment to CRM. The code compiled, but ILMerge fails. This process works on other developers machines but not mine.

I am using Visual Studio 2015, Windows 10, and building against .NET 4.5.2.

All of the projects are compiling with AnyCPU.

Resolved assembly reference 'System.Runtime.Caching' to 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319..\v4.0.30319\System.Runtime.Caching.dll'. (Used framework directory.)

An exception occurred during merging: Unable to load DLL 'mscorsn.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at System.Compiler.Writer.MscorsnStrongNameSignatureGeneration(String wszFilePath, String wszKeyContainer, Byte[] pbKeyBlob, Int32 cbKeyBlob, IntPtr ppbSignatureBlob, IntPtr pcbSignatureBlob) at System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName) at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module) at ILMerging.ILMerge.Merge() at ILMerging.ILMerge.Main(String[] args)

My Post-build event arguments are:

if "$(ConfigurationName)" == "Debug No ILMerge" goto :exit REM **** Create ILMerge Directory **** md "$(TargetDir)IlMerge" REM **** Delete Previous Log **** del "$(TargetDir)IlMerge\Log.txt" REM **** Run IlMerge **** "$(SolutionDir)packages\ILMerge.2.14.1208\tools\ILMerge.exe" /log:"$(TargetDir)IlMerge\Log.txt" /keyfile:"$(ProjectDir)Client.Xrm.Plugins.Key.snk" /targetplatform:v4 /out:"$(TargetDir)IlMerge\$(TargetFileName)" "$(TargetPath)" "$(TargetDir)DLaB.Common.dll" "$(TargetDir)DLaB.Xrm.2015.dll" "$(TargetDir)Client.Xrm.dll" "$(TargetDir)Applications.Web.Security.dll" "$(TargetDir).Domain.dll" "$(TargetDir)Newtonsoft.Json.dll" :exit

I can locate mscorsn.dll manually on my computer and drop it into the local folder. ILMerge picks it up but depending on which version I use (there are 4-5 different copies of it within Windows) it will either outright fail or state it was unable to sign the final dll.

I have tried pointing the targetplatform towards specific .NET folders that have the mscorsn.dll file to no avail.


Solution

  • I found the answer. It seems that ILMerge requires .NET 3.5 and that is not present on Windows 8, 8.1 or 10 by default. After installing .NET 3.5, ILMerge worked perfectly.

    • Programs and Features ->
    • Turn Windows features on or off ->
    • .NET Framework 3.5 (includes .NET 2.0 and 3.0)