WebApi
WebApi copied to clipboard
Microsoft.AspNet.OData version 7.5.15 exception (Method not found: 'System.IServiceProvider ...)
Microsoft.AspNet.OData version 7.5.15 throws exception:
Exception type: HttpException Exception message: Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
Assemblies affected
Microsoft.AspNet.OData v.7.5.15
Reproduce steps
Project ASP.NET MVC 5 with .NET Framework 4.8, VS 2022 on Windows 10 Pro 21H2. The exception happens after update Microsoft.AspNet.OData 7.5.14 to a version 7.5.15.
Expected result
Normally the update should not effect the project.
Actual result
After update the compilation processed with no errors, the exception happens trying to launch a project in browser:
Additional detail

I have same issue using this extention method:
public static class HttpConfigExt
{
public static ODataRoute CustomMapODataServiceRoute(this HttpConfiguration configuration, string routeName,
string routePrefix, IEdmModel model)
{
var routingConventions = ODataRoutingConventions.CreateDefaultWithAttributeRouting(routeName, configuration);
routingConventions.Insert(0, new WebPropertyRoutingConvention ());
return configuration.MapODataServiceRoute(routeName, routePrefix, builder =>
builder.AddService(ServiceLifetime.Singleton, sp => model)
.AddService<IEnumerable<IODataRoutingConvention>>(ServiceLifetime.Singleton, sp => routingConventions));
}
}
@aimi617 and @premiaware
Basically, 7.5.15 simply includes https://github.com/OData/WebApi/pull/2650 fix. I tried to fix the 'null reference'.
I actually watched 'https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/DefaultContainerBuilder.cs#L90' as
try
{
return services.BuildServiceProvider();
}
catch (MissingMethodException)
{
It should catch the MissingMethodException. I don't know what happened.
Would you please share me with your csproj file? Or if you can share with me your repro, it could be better for me to dig more. Thanks.
The exception throws on a line with "config.EnableDependencyInjection();", see also attachment aspnet_7.5.15_error.zip
Here is a fragment of WebApiConfig.cs:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var containerBuilder = new DefaultContainerBuilder();
config.UseCustomContainerBuilder(() => containerBuilder);
config.EnableDependencyInjection();
config.Formatters.InsertRange(0, ODataMediaTypeFormatters.Create());
@aimi617 It's weird, the exception is 'Exception Details: System.MissingMethodException', but i catch 'MissingMethodException'.
It should go into the catch block.
@aimi617 What's your 'csproj' content? Would you please share it with me?
That's a copy of .csproj file: cloudtest.zip
@aimi617 Your project is referencing 7.5.14. Did you give me a wrong csproj file?
<PackageReference Include="Microsoft.AspNet.OData">
<Version>[7.5.14]</Version>
</PackageReference>
Could you please double-check it? or Would you please try to use 7.5.15 version?
By the way, I noticed you are still referencing 5.7.0.
<PackageReference Include="Microsoft.AspNet.WebApi.OData">
<Version>5.7.0</Version>
</PackageReference>
Any reason why do you include 5.7 and 7.5.14 together?
Thanks for mentioning Microsoft.AspNet.WebApi.OData, it was a leftover from the previous OData version and we removed it, as well as Microsoft.AspNet.OData [7.5.14] constraint. Here is updated .csproj file with 7.5.15, cloudtest2.zip. Compilation was fine anyway the same exception still happens.
As a workaround you can downgrade your Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.DependencyInjection.Abstractions package to version 1.0 and it will works.
This is pckaging issue.
7.5.15 assembly references 7.11.0 version of Micorsoft.OData.Edm, Micorsoft.OData.Edm and Micorsoft.OData.Core assemblies, but nuget nuspec still reference 7.10.0. Even more - 7.11.0 wasn't released on nuget
It's weird, really Micorsoft.OData.Core 7.11.0 is not listed on nuget.org (the latest one is 7.10.0), but VS 2022 shows Micorsoft.OData.Core latest stable is 7.11.0. Besides the compilation and a project work fine with combination of Micorsoft.OData.Core 7.11.0 and Microsoft.AspNet.OData 7.5.14.
I see now. 7.11 was delisted (https://www.nuget.org/packages/Microsoft.OData.Core/7.11.0) and because nuspec allows 7.10 - it is now picked by nuget clients. This now gives compilation error due to unmatching versions under .net framework without binding redirects.
In your case you were able to donwload it to cache before delisting
It's interesting, 7.11.0 marked as deprecated but VS 2022 shows it as latest stable. Thanks for info, we'll downgrade back to 7.10.0.
Any news on this topic?! Updated Microsoft.OData.Core to version 7.12.1 and the problem still exists.
I have update to 7.5.16 the issue is the same i must download to Microsoft.AspNet.OData 7.5.14 and work.
Yes, 7.5.16 didn't resolve an issue, the same problem is here, both versions 7.5.15 and 7.5.16 crash the project.
Experiencing the same problem after attempting to update from 7.5.14 to 7.5.17.
System.MissingMethodException : Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'. at Microsoft.AspNet.OData.DefaultContainerBuilder.BuildContainer() at Microsoft.AspNet.OData.PerRouteContainerBase.CreateODataRootContainer(Action``1 configureAction) at Microsoft.AspNet.OData.PerRouteContainerBase.CreateODataRootContainer(String routeName, Action``1 configureAction) at Microsoft.AspNet.OData.Extensions.HttpConfigurationExtensions.MapODataServiceRoute(HttpConfiguration configuration, String routeName, String routePrefix, Action``1 configureAction)
7.5.17 no work! downgrade to 7.5.14 work!
Hello, just to raise the thread up - I have the same situation. 7.5.17 - doesn't work, 7.5.14 - works brilliantly
-- ... and to provide more details for other guys facing this problem and tryint to google it.
My symptoms were next - all OData requests failed returning this exception
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>
<StackTrace> at System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() at System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)</StackTrace>
</Error>
And underlining issue is incorrect initialization of OData related routes, done by already mentioned here MapODataServiceRoute() that in it's own turn is failing with
Exception type: HttpException
Exception message: Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
and thanks for detailed discussion!
Update to 7.6.1 fixed that long lasting issue, project runs normally and no error "Method not found: 'System.IServiceProvider..." anymore. Thanks to everyone for this release.
Update to 7.6.1 fixed that long lasting issue, project runs normally and no error "Method not found: 'System.IServiceProvider..." anymore. Thanks to everyone for this release.
@aimi617 Thanks for your input.