question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XAML code always generates SHA1 checksums in binaries even when csproj file says SHA256

See original GitHub issue
  • .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use dotnet --info)
  • Windows version: (winver)

The following link has all the information about what’s installed on the machine. https://github.com/actions/runner-images/blob/main/images/win/Windows2022-Readme.md

  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes/No

Unknown

  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc…)? If yes, please file the issue via the instructions here.

No.

Problem description:

I’m compiling C# code with msbuild. The .csproj file has: ChecksumAlgorithm SHA256 /ChecksumAlgorithm

Running ildasm on the binary, the manifest shows that the hash is still SHA1 via this line: .hash algorithm 0x00008004

The csc.exe compiler team (Tomas Matousek) has also confirmed that SHA1 is being used for the XAML c# code.

This bug does not repro on projects without XAML.

I’m also a Microsoft FTE so you can contact me directly if you need anything MS-internal.

Actual behavior:

Binary checksum is SHA1.

Expected behavior:

Binary checksum should be SHA256 as requested by .csproj file.

Minimal repro:

The attached repro includes the entire project folder post-build. It thus includes the full -bl “.binlog” file, the source code including auto-generated XAML source, and the final DLL and symbols. The only thing it excludes are the dependency dlls that were not compiled by my project but were instead auto-added by the build, e.g. api-ms-win-core…, PresentationFramework…, etc. (Removing these was required to bring the zip file down to below 25 MB.)

hwdrmdisabler_all_shrunk.zip

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ThomasGoulet73commented, Feb 16, 2023

I have local changes to change the “#pragma checksum” in the generated code according to the current ChecksumAlgorithm of the project.

But I’m not able to reproduce how the manifest should look like (Line .hash algorithm 0x00008004 should change) in a non-WPF project. If I create a new C# Console project, add <ChecksumAlgorithm>SHA256</ChecksumAlgorithm> to the .csproj, build the project and ildasm the output assembly, the line .hash algorithm 0x00008004 never changes. @tmat Do you have some pointers on what I should do to be able to see the line .hash algorithm 0x00008004 change ?

0reactions
tmatcommented, Feb 16, 2023

You can ignore the value of .hash algorithm. It specifies a different hash, which is always SHA1. See ECMA-335 specification, paragraph II.6.2.1.1.

The source document hash algorithm that #pragma checksum specifies is written to the PDB. You can use a tool like pdb2xml to display the content of the PDB file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Get a file SHA256 Hash code and Checksum
The purpose of a checksum is to allow you to check if a file has changed between the time you originally wrote it,...
Read more >
How to have app.xaml & *.xaml files listed in .csproj when ...
I am using Microsoft's upgrade assistant to migrate projects from 4.5 to 6.0. I am able to have ".cs" files included in the...
Read more >
Making Sense of the Metadata: Clustering 4000 ...
So I'm going to create a string first that will define all the ... I'll even look out for some tags I'm interested...
Read more >
C# Language
Create a new console application with dotnet new console. This will produce two files: hello_world.csproj. <Project Sdk="Microsoft.NET.Sdk">.
Read more >
MetaDefender Core v4.17.3
Welcome to the Metadefender v4 guide. This guide is intended to provide the information you need to: Install, configure, and manage Metadefender Core...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found