mscorsn.dll 使用 ILMerge 时不加载

mscorsn.dll doesn't load when using ILMerge

我在具有管理员权限的 cmd 上使用以下命令:

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"

我在日志文件末尾收到以下错误:

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)

由于我的目标框架是 v4,我的文件夹是 "v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319",我检查了那里是否存在 mscorsn.dll;它存在。

那么,可能是什么问题?你能帮忙吗?

删除 /keyfile 参数有效。我想签名是另一个问题。不知道如何解决这个问题,但至少它是这样工作的。

我遇到了同样的问题并设法解决了。

最初我生成了一个 .PFX 文件来在 Visual Studio 中签署我的程序集(使用项目属性 window 中的签名选项卡)。然后,我将 public 密钥从 .PFX 文件提取到 .SNK 文件中(使用 sn.exe)。

当我尝试使用 ILMerge.exe 并使用生成的 .SNK 文件时,我会收到 "Unable to load DLL 'mscorsn.dll'" 错误。

我通过删除 .PFX 和生成的 .SNK 文件修复了它。 然后我生成了一个新的 .SNK 文件如下(在 VS 中):

  • 项目属性 > 签名
  • 选择强名称密钥文件:<New>
  • 指定 .SNK 文件的文件名。
  • 取消选中“使用密码保护我的密钥文件”<这似乎可以解决问题。

这生成了一个新的 .SNK 文件,当我将该文件与 ILMerge 一起使用时,错误消失了。

HTH

同样的问题。 这个答案 对我有帮助。

(简而言之:ilmerge 需要安装 .NET3.5)

/keyfile 之后添加 /delaysign 开关。这样就可以了。

我苦苦思索了 2 天,试图在我的机器上解决这个问题,终于找到了答案。此处粘贴的任何建议都没有任何效果。我终于搜索了 IlMerge github 并找到了一个 post 关于可能连接到 MachineKeys 文件夹没有适当的权限。

如果你们中的任何人遇到同样的问题并且没有任何效果,请转到此目录: C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys

并为 MachineKeys 文件夹设置读写权限:

Permissions on MachineKeys folder

这个 link 帮助我正确设置:

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