Skip to content

Consolidation of AssemblyBuilderAccess when generating dynamic assemblies#2119

Merged
neuecc merged 1 commit into
MessagePack-CSharp:developfrom
MarcusChr:develop
Jan 27, 2025
Merged

Consolidation of AssemblyBuilderAccess when generating dynamic assemblies#2119
neuecc merged 1 commit into
MessagePack-CSharp:developfrom
MarcusChr:develop

Conversation

@MarcusChr

Copy link
Copy Markdown

Hi.

I was recently upgrading MassTransit's referenced version of MessagePack to the latest major version, when I discovered some tests were failing for ONLY for .NET Framework 4.7.2, due to the following exception:

System.NotSupportedException: A non-collectible assembly may not reference a collectible assembly.

Upon some research I found the cause, which appeared to be a MassTransit generating dynamic assemblies that are collectible, while MessagePack's dynamic assemblies are non-collectible.

Please see my discussion for my MassTransit PR: MassTransit/MassTransit#5726
Additionally, I found an earlier issue for MessagePack involving the same issue for .NET 5, rather than .NET Framework 4.7.2: #1150.

The PR that resolved the mentioned issue only affects non-framework builds, so I am curious if there is a specific reason why the .NET Framework builds do not share the same AssemblyBuilderAccess flag.

With these changes, both MessagePack & MassTransit pass their respective tests, so I would love to hear your thoughts and concerns.

@MarcusChr

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@neuecc

neuecc commented Jan 24, 2025

Copy link
Copy Markdown
Member

I've kept the Save method primarily for debugging purposes (to check the generated IL).
https://github.com/MessagePack-CSharp/MessagePack-CSharp/blob/master//src/MessagePack/Internal/DynamicAssembly.cs#L61-L62
and saved assembly run to PEVerify
https://github.com/MessagePack-CSharp/MessagePack-CSharp/blob/master//sandbox/DynamicCodeDumper/Program.cs#L94-L114

Since Save wasn't supported in .NET(Core) for a long time, I had only enabled it for .NET Framework.
However, now that .NET 9 finally supports Save, I'm actually thinking about switching to using Save.
dotnet/runtime#15704

@neuecc

neuecc commented Jan 24, 2025

Copy link
Copy Markdown
Member

However, since this is for debugging purposes, and the demand has decreased significantly after migrating to Source Generator, it would be acceptable to change it to Collect.

@neuecc neuecc merged commit 524fd55 into MessagePack-CSharp:develop Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants