ASP.NET Web API: Non-descriptive 500 Internal Server Error

前端 未结 10 1288
难免孤独
难免孤独 2020-12-07 16:08

As title says, I’ve got 500 Internal Server Error from GET request to an IQueryable action. The body of the error is empty. That error happens after my action returns result

10条回答
  •  难免孤独
    2020-12-07 16:49

    Post RC, this issue was fixed and you will be getting error details also apart from the 500 Internal Server Error. (This issue is fixed for Web Host scenarios only though).

    You could do the following to get the details of the actual exception which might be occurring during a formatter's WriteToStream method.

    ObjectContent> responseContent = new ObjectContent>(db.Products.Include(p => p.ProductSubcategory).AsEnumerable(), new XmlMediaTypeFormatter()); // change the formatters accordingly
    
                MemoryStream ms = new MemoryStream();
    
                // This line would cause the formatter's WriteToStream method to be invoked.
                // Any exceptions during WriteToStream would be thrown as part of this call
                responseContent.CopyToAsync(ms).Wait();
    

提交回复
热议问题