0
votes

I had a problem running my C# application throwing the following error when trying to use a certain reference as follows:

Could not load file or assembly 'My3rdPartyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)"

Then I followed this answer for signing the assembly in question.

I can confirm via Visual Studio and Sn as well that my DLL is now definitely signed and has a strong name.

However I am seeing 2 things:

  1. On my signed version of the application I still get the same error as above as if the assembly does not have a strong name.
  2. On my unsigned version which was working fine until now with the unsigned DLL, it now throws the same error with the signed version of the DLL.

I am out of clue on what could be the reason.

Thx for the help.

1
Are all the assemblies that My3rdPartyAssembly references also strongly signed? This includes other assemblies you may have written. So all the recursively referenced assemblies will need to have a strong name.Polyfun
Yes, i checked this, they are also signedisaac.hazan
I'm bumping this because I have the same problem. Is it possible that the referenced assemblies are not targeted correctly? maybe we're still targeting the previously unsigned build even after signing itCraftedGaming

1 Answers

1
votes

It turns out that I was able to solve it. I was updating the third-party library (the assembly that I want to sign) so that it can work well with my .exe BUT it gets replaced by an unsigned version that came from the NuGet package.

You'll have to update the .dll in the following location: .dll location

I will have instruction for an example package named WPFCustomMessageBox.dll. Follow the ff. steps to update the package and have it reflect on the debug folder:

  1. Open cmd in the path provided above.
  2. Type the ff. You should organize the path in your system as your folder structure and where your files are located may not be the same as mine:

a. This one gets the necessary files from the .dll

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\Ildasm.exe" /all /out=WPFCustomMessageBox.il WPFCustomMessageBox.dll

b. I'm not sure what this one does but it preps the file for the next command.

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Ilasm.exe" "WPFCustomMessageBox.il" /dll /resource="WPFCustomMessageBox.res" /key="publickey.snk"

c. This one creates the signed .dll

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\sn.exe" -R "WPFCustomMessageBox.dll" "pair.pfx"

  1. Type the password for your .pfx file and it should make the signed .dll.

I've tested this method with the aid from Adding a Strong Name to a Third-Party Assembly. The next time you compile, the former unsigned .dll that gets compiled/copied over to the Debug folder should be signed. Hope this helps :)