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.

DataProtection isn't linker friendly

See original GitHub issue

Here are the warnings:

C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\RegistryPolicyResolver.cs(40,47): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.PopulateOptions(Object,RegistryKey): The return value of method 'System.Object.GetType()' with dynamically accessed member kinds 'None' is passed into the implicit 'this' parameter of method 'System.Type.GetProperties()' which requires dynamically accessed member kinds 'PublicProperties'. To fix this add DynamicallyAccessedMembersAttribute to it and specify at least these member kinds 'PublicProperties'. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\RegistryPolicyResolver.cs(57,29): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.PopulateOptions(Object,RegistryKey): Reflection call 'System.Type.GetType(String,Boolean)' inside 'Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.PopulateOptions(Object,RegistryKey)' was detected with unknown value for the type name. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\RegistryPolicyResolver.cs(82,25): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.ReadKeyEscrowSinks(RegistryKey): Reflection call 'System.Type.GetType(String,Boolean)' inside 'Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.ReadKeyEscrowSinks(RegistryKey)' was detected with unknown value for the type name. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\SimpleActivator.cs(31,13): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.SimpleActivator.CreateInstance(Type,String): Reflection call 'System.Type.GetType(String,Boolean)' inside 'Microsoft.AspNetCore.DataProtection.SimpleActivator.CreateInstance(Type,String)' was detected with unknown value for the type name. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\SimpleActivator.cs(37,17): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.SimpleActivator.CreateInstance(Type,String): The return value of method 'System.Type.GetType(String,Boolean)' with dynamically accessed member kinds 'None' is passed into the implicit 'this' parameter of method 'System.Type.GetConstructor(Type[])' which requires dynamically accessed member kinds 'PublicParameterlessConstructor'. To fix this add DynamicallyAccessedMembersAttribute to it and specify at least these member kinds 'PublicParameterlessConstructor'. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\SimpleActivator.cs(40,21): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.SimpleActivator.CreateInstance(Type,String): The return value of method 'System.Type.GetType(String,Boolean)' with dynamically accessed member kinds 'None' is passed into the parameter #0 of method 'System.Object System.Activator::CreateInstance(System.Type)' which requires dynamically accessed member kinds 'PublicParameterlessConstructor'. To fix this add DynamicallyAccessedMembersAttribute to it and specify at least these member kinds 'PublicParameterlessConstructor'. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\SimpleActivator.cs(45,13): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.SimpleActivator.CreateInstance(Type,String): The return value of method 'System.Type.GetType(String,Boolean)' with dynamically accessed member kinds 'None' is passed into the implicit 'this' parameter of method 'System.Type.GetConstructor(Type[])' which requires dynamically accessed member kinds 'PublicConstructors'. To fix this add DynamicallyAccessedMembersAttribute to it and specify at least these member kinds 'PublicConstructors'. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\SimpleActivator.cs(53,13): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.SimpleActivator.CreateInstance(Type,String): The return value of method 'System.Type.GetType(String,Boolean)' with dynamically accessed member kinds 'None' is passed into the parameter #0 of method 'System.Object System.Activator::CreateInstance(System.Type)' which requires dynamically accessed member kinds 'PublicParameterlessConstructor'. To fix this add DynamicallyAccessedMembersAttribute to it and specify at least these member kinds 'PublicParameterlessConstructor'. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\TypeForwardingActivator.cs(54,17): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.TypeForwardingActivator.CreateInstance(Type,String,Boolean&): Reflection call 'System.Type.GetType(String,Boolean)' inside 'Microsoft.AspNetCore.DataProtection.TypeForwardingActivator.CreateInstance(Type,String,Boolean&)' was detected with unknown value for the type name. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\TypeForwardingActivator.cs(54,17): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.TypeForwardingActivator.CreateInstance(Type,String,Boolean&): Reflection call 'System.Type.GetType(String,Boolean)' inside 'Microsoft.AspNetCore.DataProtection.TypeForwardingActivator.CreateInstance(Type,String,Boolean&)' was detected with unknown value for the type name. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\AuthenticatedEncryption\ManagedAuthenticatedEncryptorFactory.cs(128,51): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ManagedAuthenticatedEncryptorFactory.AlgorithmActivator.AlgorithmActivatorCore<T>.AlgorithmActivatorCore`1(): The generic parameter 'T' from 'Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ManagedAuthenticatedEncryptorFactory.AlgorithmActivator.AlgorithmActivatorCore<T>' with dynamically accessed member kinds 'None' is passed into the generic parameter 'T' from 'System.Activator.CreateInstance<T>()' which requires dynamically accessed member kinds 'PublicParameterlessConstructor'. To fix this add DynamicallyAccessedMembersAttribute to it and specify at least these member kinds 'PublicParameterlessConstructor'. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]
C:\dev\git\aspnetcore\src\DataProtection\DataProtection\src\AuthenticatedEncryption\ConfigurationModel\ManagedAuthenticatedEncryptorDescriptorDeserializer.cs(73,17): Trim analysis warning IL2006: Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.ManagedAuthenticatedEncryptorDescriptorDeserializer.FriendlyNameToType(String): Reflection call 'System.Type.GetType(String,Boolean)' inside 'Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.ManagedAuthenticatedEncryptorDescriptorDeserializer.FriendlyNameToType(String)' was detected with unknown value for the type name. [C:\Users\davifowl\source\repos\WebApplication60\WebApplication60\WebApplication60.csproj]

Generally, DataProtection tries to load types from configuration, but these types are part of data protection itself so we can preserve these types so that loading works. Funnily enough, if we used the DI system, this wouldn’t be a problem 😄

Components with dependencies on DataProtection:

  • Microsoft.AspNetCore.Authentication.Cookies
  • Microsoft.AspNetCore.Session
  • Microsoft.AspNetCore.Authentication
  • Microsoft.AspNetCore.Components.Web.Extensions
  • Microsoft.AspNetCore.Antiforgery
  • Microsoft.AspNetCore.Mvc.ViewFeatures
  • Microsoft.AspNetCore.Components.Server

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
HaoKcommented, May 11, 2021

Update: I tried deleting all the code related to the windows implementations of SP800 so

  • Anything CngCbc and CngGcm related, the factories, the config, the deserlization:

This resulted in the following differences in Microsoft.AspNetCore.DataProtection.dll size: net6.0 (before 154KB after 143 KB) = -11KB net461 (before 151 kb after 140 KB) -11KB netstandard (before 151 kb after 140 KB) -11KB

So looks like it saves around 11 KB, or around 7%

1reaction
GrabYourPitchforkscommented, Apr 12, 2021

Honestly this seems doable to me. Might have to invent some tricks to help get the ball rolling, but nothing here immediately stands out as being impossible to trim.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does data protection 'by design' and 'by default' mean?
By default, companies/organisations should ensure that personal data is processed with the highest privacy protection (for example only the data necessary ...
Read more >
What are the Five Fundamentals of Data Privacy and ...
Understanding the five fundamentals of Data Privacy and Data Protection regulations will help businesses identify their regulatory risks, create ...
Read more >
Data Privacy & Web Accessibility Compliance: What's The ...
Both data privacy and web accessibility compliance are necessary to businesses of all sizes. But what is the link between them?
Read more >
Congress Might Actually Pass ADPPA, the American Data ...
The ADPPA, a privacy bill with bipartisan support, might finally give the US a strong federal data protection law.
Read more >
GDPR and HIPAA Compliance – Do They Overlap?
GDPR applies to all sensitive personal data, while HIPAA deals with only Protected Health Information (PHI). Security is the core of both GDPR...
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