mscorsn.dll doesn't load when using ILMerge


I'm using the following command on cmd with Administrator priviliges:

ILMerge.exe  /wildcards /log:ILMerge.log /allowdup 

And I'm getting the following error at the end of the log file:

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)

Since my targetframework is v4 and my folder is "v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319", I checked if mscorsn.dll exists there; and it exists.

So, what can be the problem? Can you please help?

asked on Stack Overflow Mar 25, 2016 by rebulanyum

5 Answers


I had the same problem and managed to fix it.

Originally I generated a .PFX file to sign my assembly in Visual Studio (using the Signing tab in the project properties window). I then extracted the public key from the .PFX file into a .SNK file (using sn.exe).

When I tried to use ILMerge.exe and use the generated .SNK file I would get the "Unable to load DLL 'mscorsn.dll'" error.

I fixed it by deleting the .PFX and generated .SNK files. I then generated a new .SNK file as follows (in VS):

  • Project Properties > Signing
  • Choose a strong name key file: <New>
  • Specify the file name for the .SNK file.
  • Uncheck `Protect my key file with a password' < This seemed to do the trick.

This generated a new .SNK file and when I used that file with ILMerge the error disappeared.


answered on Stack Overflow Dec 6, 2016 by colivier

the same issue. This answer Unable to load DLL mscorsn.dll with ILMerge helped to me.

(shortly: ilmerge requires .NET3.5 to be installed)

answered on Stack Overflow Mar 14, 2018 by grim.ub

Add /delaysign switch after the /keyfile . This will do the trick.

answered on Stack Overflow Mar 26, 2018 by Praveen Singh

I was pulling my hair out for 2 days straight trying to solve this on my machine and finally found the answer. Nothing worked from any of the suggestions pasted here. I finally searched the IlMerge github and found a post regarding the possible connection to MachineKeys folder not having proper permissions.

If anyone of You has the same issue and nothing works, please go to this directory: C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys

And set the permissions to Read AND Write for MachineKeys folder:

Permissions on MachineKeys folder

This link helped me in setting the properly:

answered on Stack Overflow Aug 10, 2020 by ksiadz_robert666

Removing the /keyfile argument worked. Well signing is another issue I guess. Don't know how to solve this but at least it worked this way.

answered on Stack Overflow Mar 25, 2016 by rebulanyum

User contributions licensed under CC BY-SA 3.0