0
Der folgende Code funktioniert, wenn ich ihn von Visual Studio auf meinem Laptop starte. Aber wenn auf IIS auf einem Server 2016 Windows-Einsatz erhalte ich ein 500-Fehler und eine Exception (.NET Framework 4.7):ObjectContent kann nicht in HttpContent umgewandelt werden
ExceptionMessage: "Error getting value from 'Content' on 'System.Net.Http.HttpResponseMessage'." ExceptionType : "Newtonsoft.Json.JsonSerializationException" InnerException ExceptionMessage: "Unable to cast object of type 'System.Net.Http.ObjectContent' to type 'System.Net.Http.HttpContent'." ExceptionType : "System.InvalidCastException"
public HttpResponseMessage Get()
{
// Entities is the Entity Framework context
// Sessions is a proprietary table and has nothing to do with ASP.NET sessions
var content = new Entities().Sessions
.AsEnumerable()
.Select(t =>
{
return new
{
t.Id,
t.SessionId,
t.StartTime,
t.EndTime
};
});
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new ObjectContent(typeof(IEnumerable), content, new JsonMediaTypeFormatter())
};
}