-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trimmer removes implementation of members of nested types #2185
Comments
PublicNestedTypes wasn't very useful because it only kept the hollowed out type without any members. This changed recently in #2133 to align with your expectations (the type will be kept along with all its members). I'm not sure of the logistics of when this will show up in .NET 6 previews/RC, but we definitely want it to land in .NET 6. You could try grabbing the latest SDK out of the main branch https://github.com/dotnet/installer#installers-and-binaries - maybe it's already included. |
It looks like this may already be in the current main, which is version rc.1.21381.5. |
Thanks for checking! Is it okay to close this or is there something else that's not working right for the nested types? |
Good to close. I thought there was one more thing still not working but it turns out the function I was calling doesn't specify either of |
This prevents nested types - e.g. child objects or arrays of child objects - from being removed by the linker when an application is trimmed. This only works at the moment in current unreleased versions of the .NET SDK (e.g. .NET 6 rc.1.21381.5). It does not work in any publicly released preview up to and including .NET 6 Preview 6. See dotnet/linker#2185 for more information.
I am trying to update https://github.com/steamre/steamkit to be trim-compatible, which is a heavy ask since it depends on a lot of reflection, particularly to serialize and deserialize messages, which are done through the protobuf-.net library.
I have applied the following attribute in order to ensure that the key parts of message types do not get trimmed:
In practice I have made a constant for all these values so I only have to add
[DynamicallyAccessedMembersAttribute(Trimming.ForProtobufNet)]
to the relevant code, and defined the following centrally:However, a trimmed consuming application crashes with the following error:
Examining the trimmed version of SteamKit2.dll shows that the nested type still exists, however its members have been trimmed out of existence by replacing their actual implementation with throwing an exception:
The final IL for this type is:
As a workaround I have switched the attributes to use
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
, which leaves the property implementations intact, but this seems a bit strange.Surely
DynamicallyAccessedMemberTypes.PublicNestedTypes
should be enough? There aren't any further member types that I can specify, such asDynamicallyAccessedMemberTypes.PublicNestedTypesPublicProperties
etc.The text was updated successfully, but these errors were encountered: