我们有一个名为 TraceWriter 的自定义Web API ITraceWriter 实现,在Application_Start中以通常的方式注册为服务。
将Web API项目升级到Web API 2后,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派生的,那么问题是什么呢?
答案 0 :(得分:1)
TraceWriter实现位于另一个项目中,该项目仍引用 System.Web.Http,Version = 4.0.0.0 。在此项目中安装最新的 Microsoft.AspNet.WebApi.Core 包解决了这个问题。