ninject / Ninject

the ninja of .net dependency injectors
http://ninject.org/
Other
2.68k stars 530 forks source link

Dependency with a default (null) argument result in InvalidProgramException when targeting net6.0 #386

Closed WGroenestein closed 2 years ago

WGroenestein commented 3 years ago

When you have a dependency with a default (null) argument and have null injection enabled on the kernel, when targeting net6.0, it will throw an InvalidProgramException (Common Language Runtime detected an invalid program). On net5.0 it succeeds happily.

An example of a dependency with the scenario:

class ClassWithOptionalArgument
{
    public ClassWithOptionalArgument(string keyPrefix = null)
    {
        Console.WriteLine(keyPrefix);
    }
}

A full repro can be found here: Repro repo

scott-xu commented 2 years ago

Thanks for reporting the issue. The bug is fixed. You can try it out from CI build: https://ci.appveyor.com/project/Ninject/ninject/builds/43200302/artifacts