-
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
Changes from all commits
fd57788
5f49e79
ac4a9d2
0eba5b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.")] | ||
private void UseStartup([DynamicallyAccessedMembers(StartupLinkerOptions.Accessibility)] Type startupType, HostBuilderContext context, IServiceCollection services, object instance = null) | ||
{ | ||
var webHostBuilderContext = GetWebHostBuilderContext(context); | ||
|
@@ -275,12 +276,12 @@ private void UseStartup([DynamicallyAccessedMembers(StartupLinkerOptions.Accessi | |
var actionType = typeof(Action<,>).MakeGenericType(typeof(HostBuilderContext), containerType); | ||
|
||
// Get the private ConfigureContainer method on this type then close over the container type | ||
var configureCallback = GetType().GetMethod(nameof(ConfigureContainer), BindingFlags.NonPublic | BindingFlags.Instance) | ||
var configureCallback = typeof(GenericWebHostBuilder).GetMethod(nameof(ConfigureContainerImpl), BindingFlags.NonPublic | BindingFlags.Instance) | ||
.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 commentThe reason will be displayed to describe this comment to others. Learn more. Previously LINQ was used to get the first I'm guessing there is only a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Lazy and defensive. Unless we decide to break the interface, this is "safe". 😄
Correct. |
||
.MakeGenericMethod(containerType) | ||
.InvokeWithoutWrappingExceptions(_builder, new object[] { configureCallback }); | ||
} | ||
|
@@ -310,7 +311,7 @@ private void UseStartup([DynamicallyAccessedMembers(StartupLinkerOptions.Accessi | |
}); | ||
} | ||
|
||
private void ConfigureContainer<TContainer>(HostBuilderContext context, TContainer container) | ||
private void ConfigureContainerImpl<TContainer>(HostBuilderContext context, TContainer container) | ||
{ | ||
var instance = context.Properties[_startupKey]; | ||
var builder = (ConfigureContainerBuilder)context.Properties[typeof(ConfigureContainerBuilder)]; | ||
|
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 aDynamicallyAccessedMembers
attribute on theTContainerBuilder
type. The linker won't be able to see that you are filling in the TContainerBuilder withcontainerType
.Looking at the implementation In Microsoft.Extensions.Hosting, I don't see HostBuilder needing this, so I think this is safe.