I've got two third-party dlls, which both are not strongly-named. I wanted to reference these dlls in app.config
to be able to locate them once on the network and avoid copying multiple times for each application using them...As far as I understand, to reference them via assemblyBinding
in app.config
file they should be strongly-named:
<runtime>
<dependentAssembly>
<assemblyIdentity name="External" culture="neutral" publicKeyToken="xxxx"/>
<codeBase version="1.0.0.0" href="FILE://N://Lib/External.dll"/>
</dependentAssembly>
...
So I need to sign them. Thanks to .NET-fu: Signing an Unsigned Assembly (Without Delay Signing) I managed to sign them with my *.snk
file:
ildasm /all /out=Bar.il Bar.dll
ilasm /dll /key=Foo.snk Bar.il
Then I replaced references in my solution to the signed ones and set CopyLocaly
to false
. Afterwards I edited the app.config
file with the new publicKeyToken
.
However when running my application I still get FileLoadException
, saying that loader cannot find one of these dlls with publicKeyToken=null
.
So I decided that one these dlls references the other, and that reference definetely does not know anything about the signed version of the other dll.
Here comes the question: is there a way to change the reference inside the first dll to the signed version of the second one? Or my only options would be not to use app.config
for these dlls and load them manually in code with, say, Assembly.LoadFrom
?
It appeared to be quite easy in the end. In the *.il
file of the dll containing a reference to the second dll I found the following entry by the name of the second dll:
.assembly extern /*23000002*/ SecondDllName
{
.ver 1:0:0:0
}
and I changed it to
.assembly extern /*23000002*/ SecondDllName
{
.publickeytoken = (xx xx xx xx xx xx xx xx )
.ver 1:0:0:0
}
i.e. added the generated public key token.
Then I reassembled the dll with
ilasm /dll /key=Foo.snk Bar.il
And it worked.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments