LightInject integration issue
I am trying to use LightInject as IoC container in Orleans Silo and on startup it throws an error Common Language Runtime detected an invalid program.
This looks like some issues with assembly loading and the root cause of it is that LightInject can't resolve IOptionsFormatter<> (which may be separate issue).
Tested with::
- Microsoft.Orleans.Server 2.0.3
- LightInject 5.1.5
- LightInject.Microsoft.DependencyInjection 2.0.7
Integration code looks like this:
var container = new LightInject.ServiceContainer(opts);
var siloBuilder = new SiloHostBuilder()
.UseServiceProviderFactory(services =>
{
return container.CreateServiceProvider(services);
})
Full stack:
at DynamicMethod(Object[] )
at LightInject.Microsoft.DependencyInjection.PerRootScopeLifetime.CreateScopedInstance(Func`1 createInstance)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at DynamicMethod(Object[] )
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Orleans.Runtime.SiloOptionsLogger.OnStart(CancellationToken token) in D:\build\agent\_work\18\s\src\Orleans.Runtime\OptionsLogger\OptionsLogger.cs:line 22
at Orleans.LifecycleExtensions.Observer.OnStart(CancellationToken ct)
at Orleans.Runtime.SiloLifecycleSubject.MonitoredObserver.OnStart(CancellationToken ct) in D:\build\agent\_work\18\s\src\Orleans.Runtime\Lifecycle\SiloLifecycleSubject.cs:line 70
at Orleans.LifecycleSubject.WrapExecution(CancellationToken ct, Func`2 action) in D:\build\agent\_work\18\s\src\Orleans.Core\Lifecycle\LifecycleSubject.cs:line 103
at Orleans.LifecycleSubject.OnStart(CancellationToken ct) in D:\build\agent\_work\18\s\src\Orleans.Core\Lifecycle\LifecycleSubject.cs:line 49
Dotnet info:
> dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.300
Commit: adab45bf0c
Runtime Environment:
OS Name: Windows
OS Version: 10.0.15063
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.300\
Host (useful for support):
Version: 2.1.0
Commit: caa7b7e2ba
Full solution that can reproduce the issue can be found here: https://github.com/n-sidorov/OreansLightInjectIssueRepro
I've also opened similar issue on LightInject repo https://github.com/seesharper/LightInject/issues/432
Looks like a LighInject issue, instead of Orleans issue. Since it is LighInject cannot resolve certain type, instead of incompatibility with Orleans. Does the suggestion from LightInject solve your problem?
And so sorry for the late reply.
We changed LightInject provider, so I am not sure if it was fixed or not. Probably you should close it until further developments.
Thanks, @n-sidorov