"The type TraceWriter must derive from ITraceWriter" 升级到 Web 后 API 2

"The type TraceWriter must derive from ITraceWriter" after upgrading to Web API 2

我们有一个名为 TraceWriter 的自定义 Web API ITraceWriter 实现,以通常的方式在 Application_Start.

将WebAPI项目升级到WebAPI2后,在Application_Start中抛出HttpException:

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

当然,TraceWriter其实是派生自ITraceWriter的,问题是什么?

TraceWriter 实现位于另一个项目中,该项目仍引用 System.Web.Http,版本=4.0.0.0。在这个项目中安装最新的 Microsoft.AspNet.WebApi.Core 包解决了这个问题。