PRB: Error Message: Cryptographic Failure While Signing Assembly (328379)



The information in this article applies to:

  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition

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("snkFileName.snk")]
				
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:
"Cryptographic failure while signing assembly '...\WindowsApplication1.exe' -- 'Error reading key file 'key.snk' -- The system cannot find the file specified."

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("..\\..\\SnkFileName.snk")]
				

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

  1. Open Visual Studio .NET
  2. Create a new Microsoft Visual C# Console Application.
  3. Compile the project, and note that it compiles as you expect.
  4. Open a Visual Studio .Net command prompt, and then type the following Command: sn -k key.snk
  5. Copy the .snk file that is generated to the project directory of the Console Application.
  6. Open the AssemblyInfo.cs file of the project. Locate the assembly file info statement, and then change the statement as follows:
    [assembly: AssemblyKeyFile("key.snk")]
    					
  7. Compile the project.
You receive the error message that is described in the "Summary" section of this article.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

306296 HOW TO: Create a Serviced .NET Component in Visual C# .NET

See the following chapter from the .NET Framework Developer's Guide on the Microsoft Developer Network (MSDN) Web site:

Modification Type:MajorLast Reviewed:10/8/2002
Keywords:kbprb KB328379