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

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

Open
schwjm opened this issue Dec 8, 2020 · 0 comments

Comments

@schwjm
Copy link

schwjm commented Dec 8, 2020

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants