I refer to my original issue submitted to Autofac here. I originally thought it was an Autofac issue but turns out it is not as I can reproduce it without Autofac.
MissingMethodException 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.
public class Foo : IFoo
{
private readonly HttpClient _httpClient;
public Foo(HttpClient httpClient) => _httpClient = httpClient;
public void DoSomething() { /* No-op */ }
}
3. Reference the .NET Standard library from the ASP.NET Web API project
4. Implement a dummy controller that initialises the `IFoo` private field
```c#
public class DummyController : ApiController
{
private readonly IFoo _foo;
public DummyController() => _foo = new Foo(new HttpClient);
[HttpGet]
public IHttpActionResult Test() => Ok("a");
}
Note that I have a parameterless contructor for `DummyController`.
5. Run the ASP.NET Web API application and visit `/api/dummy/test`.
# Expected behaviour
`"a"` is returned.
# Actual behaviour
`InvalidOpeartionException` is thrown with the inner exception `MissingMethodException`.
Stack trace:
An error has occurred.An error occurred when trying to create a controller of type 'DummyController'. Make sure that the controller has a parameterless public constructor.System.InvalidOperationException at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request) at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()An error has occurred.Method not found: 'Void AutofacNetStandara.Library.Foo..ctor(System.Net.Http.HttpClient)'.System.MissingMethodException at AutofacNetStandard.Web.Controllers.DummyController..ctor() at lambda_method(Closure ) at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
Main method initailizing Foo:```c#
class Program
{
static void Main(string[] args)
{
var foo = new Foo(new HttpClient());
Console.ReadLine();
}
}
No runtime exceptions are thrown and `foo` variable is initialised correctly.
## Moving the initialisation of `Foo._httpClient` to the default constructor of `Foo` and call the empty constructor from the web project instead, like:
```c#
// In the .NET Standard 2.0 library
public class Foo : IFoo
{
private readonly HttpClient _httpClient;
public Foo() => _httpClient = new HttpClient();
public void DoSomething() { }
}
// In the ASP.NET project, targeting .NET 4.6.1
public class ValuesController : ApiController
{
private readonly IFoo _foo;
public ValuesController() => _foo = new Foo();
[HttpGet]
public IHttpActionResult Test() => Ok("a");
}
"a" is returned as expected when visiting the route /api/values/test.
The solution is already described in https://github.com/dotnet/standard/issues/481
Web applications and web sites don't support automatic binding redirect generation. In order to resolve binding conflicts, you need to double click the warning in the error list and Visual Studio will add them to your web.config file.
I created a project with the exact steps you wrote (kudos for those detailed repro steps!!) and double-clicking on the warning in the error list and confirming the dialog fixes the issue.

Thanks @dasMulli , I never thought of checking out the error list will solve my problem!
@rexcfnghk it sounds like @dasMulli (Thanks @dasMulli) helped solve this issue so I"m going to close.
@dasMulli thank you very much, it's work for me!
@dasMulli worked a treat! thanks!!
Most helpful comment