An exception of type 'System.ArgumentException' occurred in System.Web.Http.dll but was not handled in user code
Additional information: The type DummyTracer must derive from ITraceWriter.
有趣的是...... DummyTraceWriter在同一个项目中指定。 它看起来像是:
namespace Company.Project.Logic
{
using System;
using System.Net.Http;
using System.Web.Http.Tracing;
public class DummyTracer : ITraceWriter
{
public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
{
}
}
}
看起来不错?嗯......不能注册我的新类型。
httpConfiguration.Services.Replace(typeof(ITraceWriter), new DummyTracer());
失败并显示前面提到的错误消息:DummyTracer类型必须从ITraceWriter派生。
答案 0 :(得分:0)
有趣的事实。
问题是不实际的DummyTraceWriter,而是我想要替换的 ITraceWriter界面。
httpConfiguration.Services.Replace(typeof(ITraceWriter), new DummyTracer());
不知何故,这是来自Newtonsoft.Json.Serialization而不是System.Web.Http的ITraceWriter。