user1884768
user1884768

Reputation: 35

Microsoft.AspNetCore.Mvc.ViewFeatures.Infrastructure.DefaultTempDataSerializer' cannot serialize an object of type

When I'm migrating the .net core application from 2.0 to 3.1, the following method services.AddCookieTempData() is not working since it's referring assembly"AspNetCore.Mvc.CookieTempData". If we comment this code it's showing the below error message. Please let us know what is the alternate for this method.

public void ConfigureServices(IServiceCollection services) { services.AddCookieTempData();

Error Message: The 'Microsoft.AspNetCore.Mvc.ViewFeatures.Infrastructure.DefaultTempDataSerializer' cannot serialize an object of type

Upvotes: 2

Views: 13437

Answers (1)

Your question seems similar to what is reported at https://github.com/aspnet/Mvc/issues/6711. On that page, Elion writes, "TempData serializer currently supports only a limited set of data types for simplicity. It supports a few primitive types such as int, string, and bool, and simple containers of those types, such as lists."

That same page points to a work-around at Store complex object in TempData. hem's highly-upvoted answer there (https://stackoverflow.com/a/35042391/2615878) recommends using an extension method and provides sample code for such.

Upvotes: 12

Related Questions