Monday, September 12, 2011

Delay Signing a C++/CLI Assembly

This should be easy, right? Just set the link options to delay sign the assembly with an SNK file. There were two issues I ran into, which I’ll describe here.
Fixing Delay Signing in SP1

I used the /DELAYSIGN and /KEYFILE settings in the properties page for my C++/CLI project and everything compiled just fine. However, when I tried to use an object from this DLL, I got this message::

    CS1577: Assembly generation failed … does not have a strong name

This certainly wasn’t what I expected. My first step was to double-check the signing on the assembly. I used the following command-line command to check:

sn -T AssemblyName.dll


When I ran this command, it reported “AssemblyName.dll does not represent a strongly named assembly". Obviously the properties I set in the project settings dialog weren’t working. After quite a bit of searching, I found a blog post by Amit Mohindra that explained the problem, which is a change in Visual Studio 2010 SP1.

The blog post had suggestions on how to fix the problem, but it seemed like quite a bit of work. I tried another approach, which worked just fine.
Signing via AssemblyInfo.cpp

I added an new file called AssemblyInfo.cpp to my project, which has the following contents:

#include "stdafx.h"


using namespace System;
using namespace System::Reflection;


[assembly:AssemblyKeyFile("myKey.snk")];
[assembly:AssemblyDelaySign(true)];


Read more: John Socha-Leialoha's Blog
QR: delay-signing-a-c-cli-assembly.aspx

Posted via email from Jasper-Net