Skip to content
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

Emit a single warning for startup hooks #1605

Closed
mateoatr opened this issue Nov 4, 2020 · 2 comments
Closed

Emit a single warning for startup hooks #1605

mateoatr opened this issue Nov 4, 2020 · 2 comments

Comments

@mateoatr
Copy link
Contributor

mateoatr commented Nov 4, 2020

Currently we emit four different warnings related to startup hooks when trimming a template console app:

ILLink: Trim analysis warning IL2026: System.StartupHookProvider.CallStartupHook(StartupHookProvider.StartupHookNameOrPath): Calling 'System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String)' which has `RequiresUnreferencedCodeAttribute` can break functionality when trimming application code. Types and members the loaded assembly depends on might be removed.

ILLink: Trim analysis warning IL2026: System.StartupHookProvider.CallStartupHook(StartupHookProvider.StartupHookNameOrPath): Calling 'System.Reflection.Assembly.GetType(String,Boolean)' which has `RequiresUnreferencedCodeAttribute` can break functionality when trimming application code. Types might be removed.

ILLink: Trim analysis warning IL2075: System.StartupHookProvider.CallStartupHook(StartupHookProvider.StartupHookNameOrPath): The requirements declared via the 'DynamicallyAccessedMembersAttribute' on the return value of method 'System.Reflection.Assembly.GetType(String,Boolean)' don't match those on the implicit 'this' parameter of method 'System.Type.GetMethod(String,BindingFlags,Binder,Type[],ParameterModifier[])'. The source value must declare at least the same requirements as those declared on the target location it's assigned to

ILLink: Trim analysis warning IL2075: System.StartupHookProvider.CallStartupHook(StartupHookProvider.StartupHookNameOrPath): The requirements declared via the 'DynamicallyAccessedMembersAttribute' on the return value of method 'System.Reflection.Assembly.GetType(String,Boolean)' don't match those on the implicit 'this' parameter of method 'System.Type.GetMethod(String,BindingFlags)'. The source value must declare at least the same requirements as those declared on the target location it's assigned to

There's not much we can do about this, since the startup hooks are inherently linker unfriendly. We are currently introducing a new feature switch (see dotnet/runtime#36526) to help us with the trimming of StartupHookProvider - this will stop these warnings from being printed, however, in cases where the feature switch isn't used, we should probably stop printing these four warnings, which aren't that helpful to the end user, and instead print a single one that makes it clear that trimming an app which makes use of startup hooks is an unsupported scenario.

@MichalStrehovsky
Copy link
Member

You can put a RequiresUnreferencedCodeAttribute on the CallStartupHook method and there will be just a single warning. Maybe this can be moved to the runtime repo.

@ghost ghost deleted a comment from mateoatr Nov 4, 2020
@ghost
Copy link

ghost commented Nov 4, 2020

This issue was moved by mateoatr to dotnet/runtime#44256.

@ghost ghost closed this as completed Nov 4, 2020
This issue was closed.
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

No branches or pull requests

2 participants