且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET Web API:非描述性 500 内部服务器错误

更新时间:2022-06-13 09:08:37

发布 RC,此问题已修复,除了 500 内部服务器错误之外,您还将获得错误详细信息.(尽管此问题仅适用于 Web 主机方案).

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).

您可以执行以下操作以获取在格式化程序的 WriteToStream 方法期间可能发生的实际异常的详细信息.

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

ObjectContent<IEnumerable<Product>> responseContent = new ObjectContent<IEnumerable<Product>>(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();