I have a signed application that uses third party DLLs. These DLLs were not signed. - So far no problem for the first step: I just signed them (getting *.il with ildasm.exe, ajust publickeytoken in the *.il 's because they have interdependencies, and made the *.dll's with ilasm.exe)
The project now compiles fine and also starts up.
But when in my code, a class constructor of the 3rd-party-DLL is called (or something else? - was just the first thing I did), I get the error "Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations"
It seems there won't be a problem if you have the source of the DLL and can ajust in AssemblyInfo.cs by setting
[assembly: InternalsVisibleTo("MyProject.Domain.Tests, PublicKey=..."]
But: As mentioned above I have a third-party DLL I don't have the source. So no way to solve the problem like this.
Any suggestions to get this running?
I had the exact same issue.
Why it happens
InternalsVisibleTo
to make it "friend" to other assemblies, e.g. InternalsVisibleTo("OtherAssembly")
InternalsVisibleTo
attribute must specify the public keys of those other assemblies, e.g. InternalsVisibleTo("OtherAssembly, PublicKey=[key]")
InternalsVisibleTo
is not properly declared for the assembly in question, so it throws the exception.How to fix
If the "friend" assemblies aren't needed for the program execution (e.g. it's a Test assembly, which isn't deployed in production), follow these steps:
ildasm.exe ThirdParty.dll /OUTPUT=ThirdParty.il
InternalsVisibleTo
ilasm.exe ThirdParty.il /DLL /OUTPUT=ThirdParty.modified.dll /KEY=key.snk
sn.exe -k key.snk
If the "friend" assemblies are needed for the program execution, you have to sign all those friend assemblies. Then follow similar steps as above, except instead of removing InternalsVisibleTo
, you have to amend each declaration with the correct public key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With