aspnet-api-versioning: Null Reference Exception on Batch with Versioning

I pulled the sample aspne-api-versioning and tried adding $batch to the ODataBasicSample project and it did not work. I followed the instructions in the wiki but still nothing. It seems like it’s trying to obtain the IApiVersioningFeature but that’s returning a null so it’s not able to access anything else.

Here’s my setup:

public void ConfigureServices( IServiceCollection services )
        {
            services.AddControllers();
            services.AddApiVersioning(
                options =>
                {
                    options.ReportApiVersions = true;
                    options.RegisterMiddleware = false;
                } );
            services.AddOData().EnableApiVersioning();
        }

public void Configure( IApplicationBuilder app, VersionedODataModelBuilder modelBuilder )
        {
            app.UseODataBatching();
            app.UseApiVersioning();
            app.UseRouting();
            app.UseEndpoints(
                endpoints =>
                {
                    var models = modelBuilder.GetEdmModels( "api" );
                    var batchHandler = new DefaultODataBatchHandler();
                    endpoints.MapControllers();
                    endpoints.MapVersionedODataRoute( "odata", "api", models, batchHandler );
                } );
        }

Here’s the error message I get: System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=Microsoft.AspNetCore.Mvc.Versioning StackTrace: at Microsoft.AspNetCore.Mvc.Routing.ApiVersionUrlHelper.get_RouteParameter() in …\Microsoft.AspNetCore.Mvc.Versioning\Routing\ApiVersionUrlHelper.cs:line 37

image

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17

Commits related to this issue

Most upvoted comments

My goal is within the week, but it could be even days. I’m going through the open issues and seeing with other low-hanging fruit applies and can be included. 😉