locked
JsonIgnore not working RRS feed

  • Question

  • User818337214 posted

    Hi,

    I have field in class that's name is ImageFile 

            [NotMapped]
            [Required(ErrorMessage = "RequiredError")]
            [Display(Name = "Image")]
            [JsonIgnore]
            public IFormFile ImageFile { get; set; }



    An unhandled exception occurred while processing the request.

    JsonSerializationException: Could not create an instance of type Microsoft.AspNetCore.Http.IFormFile. Type is an interface or abstract class and cannot be instantiated. Path 'ImageFile.ContentDisposition', line 1, position 160.

    Thursday, October 22, 2020 10:55 AM

Answers

  • User753101303 posted

    Hi,

    And this is Newtonsoft.Json.JsonIgnoreAttribute or System.Text.Json.Serialization.JsonIgnoreAttribute? My guess is that you are using an attribute  that doesn't match the serializer.

    Not directly related but I guess that ignoring or not this property would depend anywyay on the context in which this class is used? It seems to me it would be easier to just handle IFormFile separately?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 22, 2020 11:25 AM
  • User753101303 posted

    Ok so more likely you are using the Newtonsoft serializer (was the default in ASP.NET Core 2.x) and have to use its particular attributes...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 22, 2020 12:42 PM

All replies

  • User753101303 posted

    Hi,

    And this is Newtonsoft.Json.JsonIgnoreAttribute or System.Text.Json.Serialization.JsonIgnoreAttribute? My guess is that you are using an attribute  that doesn't match the serializer.

    Not directly related but I guess that ignoring or not this property would depend anywyay on the context in which this class is used? It seems to me it would be easier to just handle IFormFile separately?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 22, 2020 11:25 AM
  • User818337214 posted

    thank you.

    this is not working for System.Text.Json.Serialization.JsonIgnoreAttribute.

    It seems to me it would be easier to just handle IFormFile separately? maybee... 

    Thursday, October 22, 2020 11:43 AM
  • User753101303 posted

    Ok so more likely you are using the Newtonsoft serializer (was the default in ASP.NET Core 2.x) and have to use its particular attributes...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 22, 2020 12:42 PM