Description
Description
If I try to resolve the IConfiguration inside a loaded plugin, the serviceProvider fails to resolve the instance, even if it is listed with its resolve-function inside the service descriptors.
I basically followed this tutorial: https://learn.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support
Changed the console app to use GenericHost to enable DI and Configuration usage.
And tried to access the IConfiguration instance inside the plugin.
Relevant output from StackTrace: Method System.Reflection.MemberInfo.get_CustomAttributes cannot be called in this context actually not related 🥴
AdditionalInfo:
IConfiguration is listed in the ServiceDescriptors with
- Lifetime = Singleton
- ServiceType = "Microsoft.Extensions.Configuration.IConfiguration"
- ImplementationFactory = Microsoft.Extensions.Configuration.IConfiguration b__0(System.IServiceProvider)
I also can not create a Scope from the injected ServiceProvider.
Reproduction Steps
- Clone the repro: https://github.com/codeaphex/pluginIConfigRepro
- Enable either the direct constructor injection of IConfiguration, or retrieval of IConfiguration from the serviceProvider in https://github.com/codeaphex/pluginIConfigRepro/blob/main/HelloPlugin/HelloCommand.cs
Expected behavior
IConfiguration should be resolved inside the plugin just like the service provider.
Actual behavior
- Get an error indicating that no type has been registered for IConfiguration
- Stack Trace shows some error saying: Method System.Reflection.MemberInfo.get_CustomAttributes cannot be called in this context
Regression?
No response
Known Workarounds
No response
Configuration
.NET 9
Windows 11
x64
Other information
No response