OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
855 stars 475 forks source link

AddOData() is not idempotent #2243

Open hfaran opened 4 years ago

hfaran commented 4 years ago

If .AddOData() is called twice, an exception is thrown. Similar to most other ASP.NET Core Add* methods, .AddOData() should be idempotent, but it is currently not.

Assemblies affected

Reproduce steps

Expected result

Actual result

The following exception is thrown on the second invocation of AddOData():

System.InvalidOperationException: 'Sequence contains no matching element'

Additional detail

An obvious suggestion to this may to be to "not call .AddOData() more than once". Sure, that would fix it, but we need to call it twice due to the way our framework is set up (the second call is required to get the IODataBuilder so that we can use aspnet-api-versioning).

marabooy commented 4 years ago

@hfaran Thanks for reporting this. found the issue is currently caused by the following lines https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNetCore.OData/Extensions/ODataServiceCollectionExtensions.cs#L78-L87

hfaran commented 4 years ago

@marabooy Thanks for the ack.