2016-06-28 3 views
7

Nach dem Upgrade von .net RC2 auf RTM muss ich einen Parameter an einen Konstruktor von JsonOutputFormatter übergeben, der von ArrayPool abgeleitet wird. Wie bekomme ich dieses Objekt? Ich ändere JsonOutputFormatter manuell, weil ich ReferenceLoopHandling konfigurieren muss.ArrayPool-Objekt für den JsonOutputFormatter-Konstruktor bereitstellen

Nur andere ähnliche Informationen, die ich ist dies finden könnte: 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... 
    }  

Antwort

6
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Shared); 

Source

In den Kommentaren:

Die JsonOutputFormatter braucht jetzt eine ArrayPool beim Erstellen Sie können in ArrayPo übergeben ol.Shared.

Ich bemerkte auch, dass es eine. Create() - Methode auf ArrayPool gibt.

var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Create()); 
Verwandte Themen