From 5ff3ae9ff44a86ae7d25a9248e7ee9d3474ba677 Mon Sep 17 00:00:00 2001 From: Sam Xu Date: Fri, 3 Jun 2022 00:01:56 -0700 Subject: [PATCH] Add MissingMethodException' --- .../DefaultContainerBuilder.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.OData.Shared/DefaultContainerBuilder.cs b/src/Microsoft.AspNet.OData.Shared/DefaultContainerBuilder.cs index 91ff05dbc0..6dabb65ff9 100644 --- a/src/Microsoft.AspNet.OData.Shared/DefaultContainerBuilder.cs +++ b/src/Microsoft.AspNet.OData.Shared/DefaultContainerBuilder.cs @@ -87,8 +87,14 @@ public virtual IServiceProvider BuildContainer() { return services.BuildServiceProvider(); } - catch + catch (MissingMethodException) { + /* "services.BuildServiceProvider()" returns IServiceProvider in Microsoft.Extensions.DependencyInjection 1.0 and ServiceProvider in Microsoft.Extensions.DependencyInjection 2.0 + * * (This is a breaking change)[https://github.com/aspnet/DependencyInjection/issues/550]. + * To support both versions with the same code base in OData/WebAPI we decided to call that extension method using reflection. + * More info at https://github.com/OData/WebApi/pull/1082 + */ + MethodInfo buildServiceProviderMethod = typeof(ServiceCollectionContainerBuilderExtensions) .GetMethod(nameof(ServiceCollectionContainerBuilderExtensions.BuildServiceProvider), new[] { typeof(IServiceCollection) });