从。net RC2升级到RTM后,我发现我需要为JsonOutputFormatter的构造函数提供一个参数,该构造函数派生自ArrayPool。我怎么得到这个物体?我手动更新JsonOutputFormatter,因为我需要配置ReferenceLoopHandling。
我能找到的唯一相关信息是: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...
}
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Shared);
来源在注释中:
JsonOutputFormatter现在在创建时需要一个ArrayPool
我还注意到在ArrayPool上有一个。create()方法。
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Create());