Provide an ArrayPool object for the JsonOutputFormatter constructor

After upgrading from .net RC2 to RTM, I need to specify a parameter to the JsonOutputFormatter constructor, which comes from ArrayPool. How to get this object? I am new to JsonOutputFormatter manually because I need to configure ReferenceLoopHandling.

Only other related information I can find is: 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... } 
+7
c # asp.net-core .net-core
source share
1 answer
 var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Shared); 

A source

In comments:

JsonOutputFormatter now needs ArrayPool when creating it, you can pass in ArrayPool.Shared.

I also noticed that .Create () method exists on ArrayPool.

 var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Create()); 
+6
source share

All Articles