Ysefwakil
Ysefwakil

Reputation: 93

System.ArgumentNullException : Value cannot be null. (Parameter 'type') OData Unit Test upgrade to .NET 6.0

I have recently upgrading to .NET 6.0 and am now experiencing a previously unseen error before in my OData Unit Test project. I am experiecing a: System.ArgumentNullException : Value cannot be null. (Parameter 'type') error when running the following unit test:

        [Fact]
        public void Startup_Configure_Ok()
        {
            // Arrange   
            ServiceCollection serviceCollection = new ServiceCollection();
            serviceCollection.AddOData();
            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            var appBuilder = new ApplicationBuilder(provider);       
            var routeBuilder = new RouteBuilder(appBuilder);
            routeBuilder.EnableDependencyInjection();

            Startup startup = new Startup(_fixture.GetConfiguration());

            // Act
            startup.Configure(appBuilder);

            // Assert
            Assert.True(true);
        }

Any suggestions?

Stack Trace:

  Message: 
System.ArgumentNullException : Value cannot be null. (Parameter 'type')

  Stack Trace: 
IntrospectionExtensions.GetTypeInfo(Type type)
DefaultContainerBuilder.BuildContainer()
PerRouteContainerBase.CreateODataRootContainer(Action`1 configureAction)
PerRouteContainerBase.CreateODataRootContainer(String routeName, Action`1 configureAction)
ODataRouteBuilderExtensions.EnableDependencyInjection(IRouteBuilder builder, Action`1 configureAction)
ODataRouteBuilderExtensions.EnableDependencyInjection(IRouteBuilder builder)
StartupUnitTest.Startup_Configure_Ok() line 43

Upvotes: 8

Views: 3945

Answers (1)

Kwang Lee
Kwang Lee

Reputation: 116

I saw the exactly same symptom and fixed by upgrading Microsoft.AspNetCore.OData version to 7.5.17.

Upvotes: 10

Related Questions