1

I'm using Swagger-Net in my .NET 4.5.1 WebAPI project and one of my API calls is causing the Swagger UI to spin forever on load before coming back with the error below.

enter image description here

Specifically, I found that using [FromUri] in combination with a complex EF entity that has references to other entities ends up causing this.

[HttpPost]
public APIResponse CreateSchool([FromUri]School school)
{
  // save school object to db
}

public partial class School  : IAuditableEntity,IEntity
{
    public School()
    {
        this.Affiliations = new HashSet<Affiliation>();
        this.SchoolAccreditations = new HashSet<SchoolAccreditation>();
        this.SchoolAdultRoles = new HashSet<SchoolAdultRole>();
        this.SchoolCareOptions = new HashSet<SchoolCareOption>();
        this.SchoolDailySessions = new HashSet<SchoolDailySession>();
        this.SchoolEligibilityRequirements = new HashSet<SchoolEligibilityRequirement>();
        // ...more hashsets

        [DataMember]
            public int SchoolID { get; set; }
        [DataMember]
            public string Name { get; set; }
        [DataMember]
            public bool Active { get; set; }
        //...more properties
    }
}

Is there a way to still use FromUri and the EF model? Or do I need to change my API call signature?

CodeCheshire
  • 710
  • 1
  • 8
  • 27
  • I would love to reproduce your error, can you provide all the objects in your model? – Helder Sepulveda Sep 29 '19 at 14:36
  • You do mention `complex EF entity` ... for those FromUri won't be my first choice, you are risking making the url too long and crashing your request... your URL should never be longer than 2,048 characters. Any longer and some browsers wont be able to load the request. – Helder Sepulveda Sep 29 '19 at 16:41
  • if you want to troubleshoot on your end start removing properties see if you can isolate what property or group of properties are causing the issue – Helder Sepulveda Sep 29 '19 at 16:44

0 Answers0