locked
Strong name and signing a C# Assembly in .NET 3.5 RRS feed

  • Question

  • Hi,
     
    I'm having problems strong name/signing an assembly, it appears that I've been pointed to some documentation that is out-of-date. It appears that there are a number of ways in which to do this. SN tool, AL tool(Available within .NET 2008 Command Prompt) and within the Project properties, the Signing tab. All do not seem to work for me I'm afraid.

    I started using the AL tool but then came across an MSDN Mag article that said that was incorrect.

    I would like an article or someone to tell me step by step how to sign an Assembly IE. DLL written in C# Visual Studio 2008.

    Can you sign direct from your KeyPair generated to your assembly? Tried: sn -R File.dll NewKey.snk DIDNT WORK

    If, not what intermediary component is needed to be created? Container? Module?

    Regards,
    Andrew
    Sunday, December 28, 2008 1:06 PM

Answers

  • It is not complaining about your .snk file, it gives up because you haven't specified any module files.  Code.  I'm not sure why you use the command line tools, but Csc.exe has a /keyfile argument too.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, January 2, 2009 12:39 PM
    Tuesday, December 30, 2008 12:36 AM
  • Right. The linker does not link other files to an existing dll. It links files to create a dll.

    For strong-name signing, I recommend just using the VS GUI. It's easy enough. You stated that it did not work; how are you checking it?

    Note that strong-name signing is completely different than authenticode signing. If you really need authenticode signing, that is more easily done using the command-line SignTool.

           -Steve
    • Marked as answer by Zhi-Xin Ye Friday, January 2, 2009 12:39 PM
    Tuesday, December 30, 2008 2:47 PM

All replies

  • Surely you got a better diagnostic from trying to use these tools than "sorry, it didn't work".  Document your problem to get a better answer than this.
    Hans Passant.
    Sunday, December 28, 2008 4:08 PM
  • I have tried to link the KP2.snk(contains both private and public key) file to assembly File.dll, using the assembly linker tool, here is what I did within the Visual Studio 2008 Command Prompt:

    al /out:File.dll /keyfile:KP2.snk /bugreport:bugreport.txt /company:"EForce Online" /copyright:"(c) All Rights Reserved" /description:"Assembly responsible for Fileystem Writes and Logging" /product:"E-2G File" /productversion:"1.0" /title:"Title" /trade:"(tm)" /target:lib

    The above produced the following result:
    ALINK: error AL1016: No valid input files were specified

    The parameters can be explained as follows:
    al /out:File.dll - My assembly
        /keyfile:KP2.snk - strong name key file
        /bugreport:bugreport.txt - bug report file
        /company:"EForce Online" - my company name
        /copyright:"(c) All Rights Reserved" - Copyright message
        /description:"Assembly responsible for Fileystem Writes and Logging" - Description of Dll
        /product:"E-2G File" - Product Name
        /productversion:"1.0" - Product Version number
        /title:"Title"         
        /trade:"(tm)" 
        /target:lib            - File.dll is a class library





    Monday, December 29, 2008 5:46 PM
  • It is not complaining about your .snk file, it gives up because you haven't specified any module files.  Code.  I'm not sure why you use the command line tools, but Csc.exe has a /keyfile argument too.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, January 2, 2009 12:39 PM
    Tuesday, December 30, 2008 12:36 AM
  • Right. The linker does not link other files to an existing dll. It links files to create a dll.

    For strong-name signing, I recommend just using the VS GUI. It's easy enough. You stated that it did not work; how are you checking it?

    Note that strong-name signing is completely different than authenticode signing. If you really need authenticode signing, that is more easily done using the command-line SignTool.

           -Steve
    • Marked as answer by Zhi-Xin Ye Friday, January 2, 2009 12:39 PM
    Tuesday, December 30, 2008 2:47 PM
  • Within my exe I have a number of referenced assembly dlls, I'm getting the error Assembly bin\Release\File.dll must be strong signed in order to be marked as a prerequisite. I have identified that the dependant Assembly File.dll needs to be signed. Therefore I have gone through the following steps:
    1) Generated sn -k key.snk  => Created a new key file
    2) Copied the assembly dll into the folder containing the .cs files
    3) To link the key file to the assembly used csc /target:library /r:File.dll *.cs /keyfile:key.snk    --- OPTION 1
        When I perform this step I get an error:
            warning CS1616: Option 'keyfile' overrides attribute
            'System.Reflection.AssemblyKeyFileAttribute' given in a source file or
            added module

    therefore I have then proceeded to use the Signing tab under Project properties of the Project(dependant File.dll) (-- OPTION 2)and then referenced my key file. Built the Project File.dll with link to key file: key.snk. Gone back to
    command line and ran:
    csc /target:library /r:File.dll *.cs

    I have then gone back to the original exe referenced the assembly(thinking it has been signed), however I still get the same error:
    Assembly: bin\Release\File.dll must be strong signed in order to be marked as a prerequisite.

    Regards,
    Andrew
    Thursday, January 15, 2009 11:05 AM
  • Not sure who wins when you see CS1616.  Edit the AssemblyInfo.cs file of your project and comment out the AssemblyKeyFile attribute.
    Hans Passant.
    Thursday, January 15, 2009 12:56 PM
  • This is a 3.5 Project, there is no AssemblyKeyFile attribute in AssemblyInfo.cs
    Thursday, January 15, 2009 2:03 PM
  • I'm afraid I added the AssemblyKeyFile attribute and its still failed, the project referencing that assembly still raises the following error:
    Error 40 Assembly 'bin\Release\File.dll' must be strong signed in order to be marked as a prerequisite. 
    Monday, January 19, 2009 8:25 AM