Closed rexcfnghk closed 6 years ago
Have you tried different things to narrow down what might be happening here? The exception is saying it can't find the constructor specified in the delegate. Since it compiles that seems like a runtime type binding problem. Autofac doesn't actually do that work, the .NET runtime does... Which means the exception is surfacing through Autofac but it's just disguising the underlying problem.
Notice the source of the missing method exception (5 lines up from bottom of stack trace) is the generated code from the delegate.
Some things to try:
The idea here is to try to determine the root cause that is being covered up by the exception. Maybe it's a missing runtime directive or something else, but hopefully some additional tests can shed light.
Thanks @tillig , it seems to be an integration issue with .NET Standard and ASP.NET, I have submitted another issue to the .NET Standard repo: https://github.com/dotnet/standard/issues/613
I'm glad you were able to track down the root cause. I'll follow that issue to see what happens, but since it's not an Autofac issue, I'll close this.
Sure, thanks for the suggestions that helped me track down the issue!
Summary
Autofac.Core.DependencyResolutionException
is thrown when resolving for a component through a delegate that returns a type defined in a .NET Standard 2.0 library, under the context of an classic ASP.NET Web API project.Steps to reproduce
public class Foo : IFoo { private readonly HttpClient _httpClient;
}
Implement the relevant container registration as follows:
/api/dummy/test
.Expected behaviour
"a"
is returned.Actual behaviour
Autofac.Core.DependencyResolutionException
is thrown.Stack trace: