Microsoft KB Archive/328379

= PRB: Error Message: Cryptographic Failure While Signing Assembly =

Article ID: 328379

Article Last Modified on 10/8/2002

-

APPLIES TO


 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer

-



This article was previously published under Q328379



SYMPTOMS
When you create an .snk file for an assembly, and you make the following changes to the AssemblyInfo.cs file: [assembly: AssemblyKeyFile(&quot;snkFileName.snk&quot;)] you save the file in the project directory of the assembly, and then you compile your project, you may receive an error message that is similar to the following:

&quot;Cryptographic failure while signing assembly '...\WindowsApplication1.exe' -- 'Error reading key file 'key.snk' -- The system cannot find the file specified.&quot;



CAUSE
The .snk file location of AssemblyKeyFile must be relative to the EXE directory or the DLL directory.



RESOLUTION
Before you compile the project, you must change the path to the .snk file. To change the .snk file location by using the path from the debug or the release directory, open the AssemblyInfo.cs file, and then replace the AssemblyKeyFile code as follows: [assembly: AssemblyKeyFile(&quot;..\\..\\SnkFileName.snk&quot;)]



STATUS
This behavior is by design.



MORE INFORMATION
In the AssemblyInfo.cs file of the project, the IDE indicates in comments that the .snk file is relative to the build path.

Steps to Reproduce the Behavior
 Open Visual Studio .NET Create a new Microsoft Visual C# Console Application. Compile the project, and note that it compiles as you expect. Open a Visual Studio .Net command prompt, and then type the following Command: sn -k key.snk  Copy the .snk file that is generated to the project directory of the Console Application.</li>  Open the AssemblyInfo.cs file of the project. Locate the assembly file info statement, and then change the statement as follows: [assembly: AssemblyKeyFile(&quot;key.snk&quot;)] </li> Compile the project.</li></ol>

You receive the error message that is described in the &quot;Summary&quot; section of this article.

<div class="references_section">