WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Microsoft.AspNet.OData version 7.5.15 exception (Method not found: 'System.IServiceProvider ...)

Open aimi617 opened this issue 3 years ago • 19 comments

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

image

aimi617 avatar Jun 04 '22 16:06 aimi617

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));
    }
}

premiaware avatar Jun 06 '22 08:06 premiaware

@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.

xuzhg avatar Jun 06 '22 16:06 xuzhg

The exception throws on a line with "config.EnableDependencyInjection();", see also attachment aspnet_7.5.15_error.zip

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 avatar Jun 06 '22 16:06 aimi617

@aimi617 It's weird, the exception is 'Exception Details: System.MissingMethodException', but i catch 'MissingMethodException'.

It should go into the catch block.

xuzhg avatar Jun 06 '22 17:06 xuzhg

@aimi617 What's your 'csproj' content? Would you please share it with me?

xuzhg avatar Jun 06 '22 17:06 xuzhg

That's a copy of .csproj file: cloudtest.zip

aimi617 avatar Jun 06 '22 19:06 aimi617

@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?

xuzhg avatar Jun 06 '22 22:06 xuzhg

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.

aimi617 avatar Jun 06 '22 23:06 aimi617

As a workaround you can downgrade your Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.DependencyInjection.Abstractions package to version 1.0 and it will works.

manoack avatar Jun 09 '22 13:06 manoack

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

MaceWindu avatar Jun 15 '22 13:06 MaceWindu

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.

aimi617 avatar Jun 15 '22 17:06 aimi617

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

MaceWindu avatar Jun 15 '22 17:06 MaceWindu

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.

aimi617 avatar Jun 15 '22 17:06 aimi617

Any news on this topic?! Updated Microsoft.OData.Core to version 7.12.1 and the problem still exists.

marsonwar avatar Aug 03 '22 10:08 marsonwar

I have update to 7.5.16 the issue is the same i must download to Microsoft.AspNet.OData 7.5.14 and work.

premiaware avatar Aug 16 '22 09:08 premiaware

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.

aimi617 avatar Aug 16 '22 18:08 aimi617

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)

jimivey avatar Aug 22 '22 22:08 jimivey

7.5.17 no work! downgrade to 7.5.14 work!

premiaware avatar Aug 29 '22 16:08 premiaware

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!

VadymLevkovskyi avatar Oct 07 '22 07:10 VadymLevkovskyi

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 avatar Oct 26 '22 01:10 aimi617

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.

xuzhg avatar Oct 26 '22 16:10 xuzhg