-
-
Notifications
You must be signed in to change notification settings - Fork 636
StrongName
Jb Evain edited this page Jan 19, 2015
·
6 revisions
It’s possible to modify a strong named assembly with Cecil, but to be able to be loaded, the assembly will have to be signed back. There’s different options here.
- By default, if you don’t specify anything, the assembly will be saved in a delay-signed form. Cecil will make some room for the strong name, but it won’t be present. You’ll have to sign the assembly back with the sn tool that comes with either the .net sdk, or Mono.
sn -R foo.dll
On .net, you can add the assembly to the list of assemblies on which the .net runtime won’t validate their strong name. That’s also done through the sn tool:
sn -Vr foo.dll
- If you have access to the key pair, you can ask Cecil to sign it directly. That’s done by specifying a
System.Reflection.StrongNameKeyPair
when writing the module:
var module = ...;
module.Write ("Foo.dll", new WriterParameters {
StrongNameKeyPair = new StrongNameKeyPair (File.ReadAllBytes ("Foo.snk"))
});
- You could decide to remove the strong name completely. But it means that every assembly which references the one you’re modifying will need to have its reference updated. To do that, you must clear its public key, and indicate that it’s not signed:
var assembly = ...;
var name = assembly.Name;
name.HasPublicKey = false;
name.PublicKey = new byte [0];
module.Attributes &= ~ModuleAttributes.StrongNameSigned;