Export (0) Print
Expand All

#pragma checksum (C# Reference)

May be used to generate checksums for source files to aid with debugging ASP.NET pages.

#pragma checksum "filename" "{guid}" "checksum bytes"



The name of the file that requires monitoring for changes or updates.


The Globally Unique Identifier (GUID) for the file.


The string of hexadecimal digits representing the bytes of the checksum. Must be an even number of hexadecimal digits. An odd number of digits results in a compile-time warning, and the directive is then ignored.

The Visual Studio debugger uses a checksum to ensure that it always finds the right source. The compiler computes the checksum for a source file, and then emits the output to the program database (PDB) file. The debugger then uses the PDB to compare against the checksum that it computes for the source file.

This solution does not work for ASP.NET projects, because the computed checksum is for the generated source file, rather than the .aspx file. To address this problem, #pragma checksum provides checksum support for ASP.NET pages.

When you create an ASP.NET project in Visual C#, the generated source file contains a checksum for the .aspx file, from which the source is generated. The compiler then writes this information into the PDB file.

If the compiler encounters no #pragma checksum directive in the file, it computes the checksum and writes the value to the PDB file.

class TestClass
    static int Main()
        #pragma checksum "file.cs" "{3673e4ca-6098-4ec1-890f-8fceb2a794a2}" "{012345678AB}" // New checksum

Community Additions

© 2014 Microsoft