-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fix some linker warnings, report others #24553
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
- Added RequiresUnreferencedCode to UseStartup that takes a string - Added some suppressions - Fixed ConfigureContainer calls - Fixed HostingStartupAttribute
src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
.MakeGenericMethod(containerType) | ||
.CreateDelegate(actionType, this); | ||
|
||
// _builder.ConfigureContainer<T>(ConfigureContainer); | ||
typeof(IHostBuilder).GetMethods().First(m => m.Name == nameof(IHostBuilder.ConfigureContainer)) | ||
typeof(IHostBuilder).GetMethod(nameof(IHostBuilder.ConfigureContainer)) |
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.
Previously LINQ was used to get the first ConfigureContainer
method for some reason. Do we know why?
I'm guessing there is only a single ConfigureContainer
on IHostBuilder
.
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.
Previously LINQ was used to get the first ConfigureContainer method for some reason. Do we know why?
Lazy and defensive. Unless we decide to break the interface, this is "safe". 😄
I'm guessing there is only a single ConfigureContainer on IHostBuilder.
Correct.
…Extensions.cs Co-authored-by: James Newton-King <[email protected]>
Co-authored-by: James Newton-King <[email protected]>
This is supported as of C# 9.0 thanks to @RikkiGibson |
@@ -234,6 +234,7 @@ public IWebHostBuilder UseStartup([DynamicallyAccessedMembers(StartupLinkerOptio | |||
return this; | |||
} | |||
|
|||
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern", Justification = "We need to call a generic method on IHostBuilder.")] |
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.
The case where this may be unsafe is if IHostBuilder.ConfigureContainer
ever puts a DynamicallyAccessedMembers
attribute on the TContainerBuilder
type. The linker won't be able to see that you are filling in the TContainerBuilder with containerType
.
Looking at the implementation In Microsoft.Extensions.Hosting, I don't see HostBuilder needing this, so I think this is safe.
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.
Follow up to #24458
The other warnings require refactoring to put attributes on code that today exists as lambdas 😢. @agocke @jaredpar I need attributes on local functions so I can put linker attributes on them.