Signing an Assembly with a Strong Name

Posted on 2005-04-28
Last Modified: 2011-04-14

I tried in signing in an assembly using the assembly linker.exe (al.exe)

This is the following cmd line which I have used in the command prompt
E:\Code Access Security\bin\Debug>al /out:Code Access Security.exe Code_Access_S
ecurity.Form1 /keyfile:sgkey.snk

and I am recieving the following error
ALINK: error AL1047: Error importing file 'E:\Code Access Security\bin\Debug\Acc
ess' -- The system cannot find the file specified.

The name of the source file which I am using is  form.cs
The name space I am using is Code_Access_Security
and the class is Form1.

please suggest me where I have went wrong and how can I resolve it.

Thanks in advance
Question by:dnlakhani
    LVL 6

    Expert Comment

    try this

    al /out:Code "Access Security.exe" Code_Access_S
    ecurity.Form1 /keyfile:sgkey.snk

    the space is probably causing the problem.
    LVL 1

    Author Comment

    this doesn't work out ..

    I have found another method where  I can do the same operation but I want to know why this does not work...!
    LVL 13

    Expert Comment

    do you have visual studio .net?
    LVL 23

    Expert Comment


    I always just add the strong name key as an assembly attribute.

    Start> RUN> "C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\sn.exe" -k C:\temp\StrongName.snk

    Then take the file and put it in the directory with all of the other source code.

    Then add this assembly attribute:

    [assembly: AssemblyKeyFile("..\\..\\StrongName.snk")]
    LVL 13

    Accepted Solution

    > I always just add the strong name key as an assembly attribute.

    that's the proper way around if you have Visual Studio, but what if you don't? that's why I asked... if you don't have VS then, open command prompt window and do following:

    C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.xxxx\Bin\al.exe /out:Code Access Security.exe Code Access Security.cs  /keyfile:sgkey.snk

    you get "file not found" because you have "Code_Access_Security.Form1" what's Form1...??? it's not a valid extension is it..? that's why I replaced it with ".cs"

    or you can compile all together and then sign it
    C:\Program Files\Microsoft.NET\SDK\v1.xxxx\Bin\CSC.exe /t:library  /out:Code_Access_Security /r:System.dll,System.Data.dll,System.Drawing.dll,System.Web.UI.dll  Code_Access_Security.cs
    LVL 13

    Expert Comment

    LVL 23

    Expert Comment


    Umm.. you shouldn't *have* to have visual studio to enter the strong name in as an assembly attribute (although it is easier).

    I guess I haven't needed to test it, but the following code should work from within any text editor:

    using System;


    namespace MyApplication
       public class MyClass
           public MyClass(){}

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now