Skip to content

Remove .mvid section.#82712

Open
teo-tsirpanis wants to merge 4 commits intodotnet:mainfrom
teo-tsirpanis:mvid-srm
Open

Remove .mvid section.#82712
teo-tsirpanis wants to merge 4 commits intodotnet:mainfrom
teo-tsirpanis:mvid-srm

Conversation

@teo-tsirpanis
Copy link
Contributor

@teo-tsirpanis teo-tsirpanis commented Mar 11, 2026

Fixes #82653.

Partially reverts #19133

As explained in the linked issue, the CopyRefAssembly task is now able to use System.Reflection.Metadata to read the reference assembly's MVID from the Module table, which means that we no longer have to duplicate it in the .mvid PE section.

This PR updates CopyRefAssembly to use SRM, and updates PeWriter to stop writing the .mvid section in reference assemblies.

Microsoft Reviewers: Open in CodeFlow

@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Mar 11, 2026
@@ -95,7 +95,7 @@ public void SourceNotAssemblyWithDestination()

Assert.True(task.Execute());

AssertEx.AssertEqualToleratingWhitespaceDifferences($$"""
AssertEx.AssertContainsToleratingWhitespaceDifferences($$"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a behavior change, as SRM will throw on invalid files, while the previous MvidReader did not. There is code in CopyRefAssembly that handles the MvidReader throwing, which makes me not sure of what the intention is.

Is this change OK, or should we update CopyRefAssembly to swallow the exceptions during MVID reading?

@teo-tsirpanis teo-tsirpanis marked this pull request as ready for review March 12, 2026 03:02
@teo-tsirpanis teo-tsirpanis requested a review from a team as a code owner March 12, 2026 03:02
@jcouv jcouv self-assigned this Mar 12, 2026
@AlekseyTs
Copy link
Contributor

This PR updates CopyRefAssembly to use SRM, and updates PeWriter to stop writing the .mvid section in reference assemblies.

Is this safe to do? Is it possible that some existing tools will stop working if the section isn't present?

@teo-tsirpanis
Copy link
Contributor Author

teo-tsirpanis commented Mar 12, 2026

From what I'm seeing here, there are a few external tools (F# and dnlib) that write an .mvid section, but none that reads it. I don't think it's likely that a tool would have a strong dependency on this section's existence, partly because it's not emitted in assemblies used at runtime.

Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for confirmation from msbuild about these dependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop reading and emitting .mvid section for reference assemblies.

4 participants