Signing a (3rd Party) complied .NET assembly

You may have referenced an assembly from your strongly named project and noticed an “Assembly generation failed — Referenced assembly does not have a strong name” exception. Or “Could not load file or assembly or one of its dependencies. A strongly-named assembly is required.” While working with an open-source component, I found that I was in this situation. In that case, I asked the primary developer if the assembly could be strongly named and he agree to do so. You may not have been so lucky.

  1. Start up the Visual Studio Command Prompt
  2. Create a .snk key file.
  3. Dis-assemble the assembly
  4. Re-Assemble using your strong-name key

You can use the following commands.

cd c:\workingdir\

sn -k sgKey.snk

 

You will need to replace originalAssembly below with the name of your assembly and drop a copy of it into c:\workingdir\. Use this pair of commands for a dll.

ildasm originalAssembly.dll /out:temp.il

ilasm temp.il /res:temp.res /dll /key:sgKey.snk /out:originalAssemblySN.dll

 

Use this pair of commands for an exe.

ildasm originalAssembly.exe /out:temp.il

ilasm temp.il /res:temp.res /key:sgKey.snk /out:originalAssemblySN.exe

 

That’s how you assign a strong name to (how to sign) an unsigned assembly!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s