Closed Amiron49 closed 3 years ago
Got it, thank you for the reproduction steps, and the fix for this will be in Lamar 5.0.3 shortly.
Because Lamar only creates a singleton once, it uses pure Reflection to build a singleton rather than wasting any time building and compiling a Func<Scope, object> to do that.
I didn't configure a dependency Lamar needed for constructing a class but Lamar swallowed the Error and tries to resolve a non existing ctor on the class and throws a System.MissingMethodException:"Constructor on type 'X' not found.", instead of serving the issue it knows about internally.
It seems like Lamar has a different Exception throwing behavior when registering something as a singleton vs the default (transient I guess). Here is a quick reproduction:
Console Output:
In my case I found the real reason by breaking on the Exception, going up the stacktrace to the closest
Lamar.IoC.Instances.ConstructorInstance.quickResolve(Scope scope)
. On theConstructorInstance
there is a PropertyErrorMessages
, explaining that it had issue with one of the ctor arguments. And looking at what exactly Lamar is doing is a call toActivator.CreateInstance
but with 0 CtorArguments (this.Arguments
is empty). But the only existing ctor is one with 1 argument, so the activator rightfully throws as the Ctor Lamar is attempting to activate does not exist.I'm 80% sure that is also the real reason for this other issue: #210
Stack Trace: