Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ysefwakil opened this issue May 19, 2022 · 6 comments · Fixed by OData/WebApi#2650
Closed
Assignees
Labels
bug Something isn't working

Comments

@ysefwakil
Copy link

ysefwakil commented May 19, 2022

Assemblies affected
ASP.NET Core OData 7.5.0

Describe the bug
Unit tests failing when upgrading to .NET 6.0
Reproduce steps
The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.

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

this is failing with the following error:
image

@ysefwakil ysefwakil added the bug Something isn't working label May 19, 2022
@habbes habbes self-assigned this May 24, 2022
@mikepizzo
Copy link
Member

@xuzhg -- this is the same error that was reported in a separate thread. Looks like there is an incompatibility between ASP.NET Core OData 7.x and .NET 6.

Since .NET 3.1 is going out of support, we need to prioritize any issue blocking migration to .NET 6.

@xuzhg
Copy link
Member

xuzhg commented May 25, 2022

@ysefwakil

The "problem" looks from this line: https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/DefaultContainerBuilder.cs#L92

'ServiceCollectionContainerBuilderExtensions' is removed or changed in .NET 6? but at my test and investigation, .NET 6 contains this class. But, not in .NET 7. It's weird.

Would you please share with me your whole repro?
At my test,

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.2">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\..\github\odata\WebApi\src\Microsoft.AspNetCore.OData\Microsoft.AspNetCore.OData.csproj" />
  </ItemGroup>

</Project>
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
            // 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);
        }
    }

    public class Startup
    {
        public Startup(/*IConfiguration config*/)
        {
            //ConfigurationManager manager = new ConfigurationManager();
            //manager.GetConnectionString("setting");
        }

        public void ConfigureService(IServiceCollection services)
        {

        }

        public void Configure(IApplicationBuilder app)
        {

        }
    }

The test works fine.

@xuzhg
Copy link
Member

xuzhg commented May 25, 2022

@ysefwakil Would you please try the nightly package, version 7.7.0.---. See details at; https://github.com/OData/WebApi#nightly-builds

@ysefwakil
Copy link
Author

After upgrading to 7.7.0 using .net6.0, my whole project fails rather than just my unit tests:

image
image

@xuzhg
Copy link
Member

xuzhg commented May 26, 2022

@ysefwakil Is it ok to share with me your repro?
If can't share, can we have a remote session to take a look at your repro together?
I am at PST. Just share with me a meeting link

xuzhg added a commit to OData/WebApi that referenced this issue Jun 2, 2022
xuzhg added a commit to OData/WebApi that referenced this issue Jun 3, 2022
@ysefwakil
Copy link
Author

Hi, I am unable to do any sessions of this sort, however I have seen a couple commits go through. Should I update to a specific version of Odata for this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants