mscorsn.dll doesn't load when using ILMerge

3

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

ILMerge.exe  /wildcards /log:ILMerge.log /allowdup 
             /targetplatform:"v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319" 
             /lib:"C:\SDK2016\SDK2016\Bin" 
             /lib:"packages\Microsoft.CrmSdk.Extensions.7.1.0.1\lib\net45" 
             /lib:"packages\log4net.2.0.5\lib\net45-full" 
             /keyfile:"Tools\Snk\XXX.snk" 
             /out:"c:\XXXALLMERGED.dll" 
             "c:\proj\alldlls\*.dll"

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?

.net
ilmerge
snk
asked on Stack Overflow Mar 25, 2016 by rebulanyum

5 Answers

6

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.

HTH

answered on Stack Overflow Dec 6, 2016 by colivier
3

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
2

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

answered on Stack Overflow Mar 26, 2018 by Praveen Singh
0

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:

https://odetocode.com/blogs/scott/archive/2020/01/12/solving-access-denied-in-crypto-machine-keys.aspx

answered on Stack Overflow Aug 10, 2020 by ksiadz_robert666
-1

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