The particular issue happens when supporting $format to ODataMediaTypeFormatter.
The controller configuration won't work with tracing enabled:
public class ODataFormatQueryAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
var formatters = controllerSettings.Formatters.Where(f =>
!f.MediaTypeMappings.OfType<QueryStringMapping>().Any(m => m.QueryStringParameterName == "$format"));
formatters.ToList().ForEach(f =>
{
f.AddQueryStringMapping("$format", "atom", "application/atom+xml");
f.AddQueryStringMapping("$format", "json", "application/json");
f.AddQueryStringMapping("$format", "xml", "application/xml");
});
}
}
The reason is because MediaTypeFormatterTracer doesn't pass MediaTypeMappings to inner formatter. When call GetPerRequestFormatterInstance, it will delegate to inner formatter to create a new one to negotiate. The new one will copy from the inner formatter which doesn't has the mappings.
The controller configuration won't work with tracing enabled:
public class ODataFormatQueryAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
var formatters = controllerSettings.Formatters.Where(f =>
!f.MediaTypeMappings.OfType<QueryStringMapping>().Any(m => m.QueryStringParameterName == "$format"));
formatters.ToList().ForEach(f =>
{
f.AddQueryStringMapping("$format", "atom", "application/atom+xml");
f.AddQueryStringMapping("$format", "json", "application/json");
f.AddQueryStringMapping("$format", "xml", "application/xml");
});
}
}
The reason is because MediaTypeFormatterTracer doesn't pass MediaTypeMappings to inner formatter. When call GetPerRequestFormatterInstance, it will delegate to inner formatter to create a new one to negotiate. The new one will copy from the inner formatter which doesn't has the mappings.