1

We have a custom Web API ITraceWriter implementation named TraceWriter, registered as a service in the usual way in Application_Start.

After upgrading the Web API project to Web API 2, an HttpException is thrown in Application_Start:

The type TraceWriter must derive from ITraceWriter.
Parameter name: service
   at System.Web.Http.Controllers.ServicesContainer.Replace(Type serviceType, Object service)

Of course, the TraceWriter actually is deriving from ITraceWriter, so what is the problem?

1 Answers1

1

The TraceWriter implementation was located in a different project, which still referenced System.Web.Http, Version=4.0.0.0. Installing the latest Microsoft.AspNet.WebApi.Core package in this project solved the problem.

  • 1
    I got caught by this by already having "using Newtonsoft.Json.Serialization"; in the class. This also has an ITraceWriter. – Bleeped Aug 30 '16 at 21:02