Don't Sign C++/CLI Assemblies with Attributes

We've already talked about using the /keyfile or /keycontainer switches to sign C# and VB assemblies instead of using the AssemblyKeyFile attribute.  When dealing with C++/CLI assemblies, using these switches becomes even more important.

The reasoning is that if the attributes are used, the assembly will be signed and then the linker will embed a manifest into it.  Obviously embedding the manifest will cause the signature to break, which will lead to C++/CLI assemblies being signed with the attributes to fail to load with a FileLoadException, saying that strong name validation of the assembly failed.

The correct way to sign a C++/CLI assembly is to use the /keyfile or /keycontainer switches to the linker.  Doing this causes the linker to embed the manifest before it signs the assembly, which keeps the signature intact.

Within Visual Studio, you can find these options on the Advanced settings of the Linker on the project properties:

VS signing dialog for C++/CLI projects