Reputation:
After upgrading from .net RC2 to RTM I find I need to supply a parameter to a constructor of JsonOutputFormatter that derives from ArrayPool. How do I get this object? I am newing JsonOutputFormatter manually because I need to configure ReferenceLoopHandling.
Only other related info I could find is this: https://github.com/aspnet/Mvc/issues/4562
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMemoryCache();
services.AddSession();
services.AddMvc();
var formatterSettings = JsonSerializerSettingsProvider.CreateSerializerSettings();
formatterSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
JsonOutputFormatter formatter = new JsonOutputFormatter(formatterSettings, ???);
services.Configure<MvcOptions>(options =>
{
options.OutputFormatters.RemoveType<JsonOutputFormatter>();
options.OutputFormatters.Insert(0, formatter);
});
//etc...
}
Upvotes: 11
Views: 3190
Reputation: 1910
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Shared);
In the comments:
The JsonOutputFormatter now needs a ArrayPool when creating it, you can pass in ArrayPool.Shared.
I also noticed there is a .Create() method on ArrayPool.
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Create());
Upvotes: 7