-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Refactor DataProtection trimming #41650
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
Conversation
Can we add a test somewhere to verify the warning experience, i.e. a trimmed app test that references a type that fails to deserialize? |
Testing trimming is difficult because you need to build a new app, publish it, then run it. However, I can add a test that verifies a type that can't be found throws the friendly error message. |
else if (type == typeof(CngCbcAuthenticatedEncryptorDescriptorDeserializer)) | ||
else if (type == typeof(CngCbcAuthenticatedEncryptorDescriptorDeserializer) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return _activator.CreateInstance<CngCbcAuthenticatedEncryptorDescriptorDeserializer>(descriptorDeserializerTypeName); | ||
} | ||
else if (type == typeof(CngGcmAuthenticatedEncryptorDescriptorDeserializer)) | ||
else if (type == typeof(CngGcmAuthenticatedEncryptorDescriptorDeserializer) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this netstandard 2.0? These APIs aren't trim friendly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it targets netstandard2.0.
What specifically isn't trim-friendly? No warnings are coming from the linker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I meant that RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
isn't recognized by the trimmer. Those branches will exist when this is trimmed and we're targeting linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I added IsOSPlatform
to suppress errors from build, not for trimming.
A couple of types won't matter. I don't think introducing a net6-window target is worth it.
This might still fail in weird ways. Even if the external type is loaded, it would be missing things that it depends on that weren't preserved. We're going to let that fail randomly in that case right? (TBH, nothing can be done about that...) |
Agreed. Nice thing is these changes are internal and conservative. If people run into problems we can't revisit them in the future. |
Hey @JamesNK! 👋🏻 I'm pretty sure these changes broke cross-version forwarding when using The code in
Since the old version of the decryptor cannot be found. I'd send a PR to fix this, but I'm not 100% sure what the intention of the change in this PR was and how to work around it. |
Hi Create an issue with what you just said. PR welcome. @amcasey is working on data protection recently. Include both of us on the issue and PR. |
Fixes #41411
Fixes #24705
Result of the discussion with Levi and Hao about how DataProtection is used:
Since custom type names are rare, this PR removes build warnings. It's possible to get runtime errors, but this change tries to make them useful.
This PR: