seesharper/LightInject

LightInject.Source does not play nice with project-level nullable reference types

schwjm opened this issue · 0 comments

LightInject.Source will emit warnings when it's pulled in but not compatible with certain project settings available in C# 8.0 and later.

Steps to reproduce

  1. Create a new .NET standard 2.1 library with the below .csproj including LightInject.Source and a stub Class1.cs file (as if created with Visual Studio)
  2. Build.
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <Nullable>enable</Nullable>
    <WarningsAsErrors>CS8601; CS8602; CS8603</WarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="LightInject.Source" Version="6.4.0" />
  </ItemGroup>

</Project>

Desired outcome

No errors, no warnings.

Actual outcome

Errors, because LightInject is seemingly written without regard to nullable reference types. Since warnings around null handling are treated as errors in this example, the build fails, so for this kind of configuration, the warnings cannot be simply ignored.

Recommendation

Include #nullable disable in the LightInject.cs file provided in the NuGet package to explicitly announce to the compiler that it is not using the "nullable context" feature (not sure if multitargeting will make this difficult).

Workarounds

  • Use LightInject instead of LightInject.Source (but then you lose out on the benefits of LightInject.Source).
  • Do not use a project level <Nullable> property, but define it on a per-file basis.