Description
I have these entity types ...
[Table("Packages", Schema = "Packaging")]
public class Package
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
[Required]
[StringLength(500)]
public string Description { get; set; }
[Required]
[StringLength(100)]
public string Category { get; set; }
[Required]
[StringLength(200)]
public string SourceApi { get; set; }
public virtual ICollection<PackageItem> Items { get; set; }
public Package() { }
public Package(string name) { Name = name; }
}
[Table("PackageItems", Schema = "Packaging")]
public class PackageItem
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
[ForeignKey("Package")]
public Guid PackageId { get; set; }
// used to determine T for data
public string Type { get; set; }
// JSON of the object being imported
public string Data { get; set; }
public virtual Package Package { get; set; }
public T Unpack<T>() { return JsonConvert.DeserializeObject<T>(Data); }
}
And this method in my OData controller ...
[HttpGet]
[EnableQuery]
public IActionResult Export([FromODataUri]int key)
{
var result = Service.Export(key);
return Ok(result);
}
When I request it with ...
HTTP GET ~/Api/Controller/Export()?$expand=Items
I get the response ...
net::ERR_SPDY_PROTOCOL_ERROR 200
... The response body appears to be empty.
In the older .Net 4.6 implementation of this same request the response comes back fine.
I'd like some guidance on debugging or fixing this.
I'm using the latest "not preview" builds from github for netcore 2.2 for the aspnet stack and the OData libs and has the following using directives (on top of my own internal dependencies) ...
using Microsoft.AspNet.OData;
using Microsoft.AspNet.OData.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
...
Which have come from Nuget packages ...
Microsoft.NetCore.App 2.2.0
Microsoft.AspNetCore.App 2.2.0
Microsoft.AspNetCore.Razor.Design 2.2.0
Microsoft.AspNetCore.OData 7.1.0
Hopefully this is relevant here as opposed to the OData side but happy to repost there or reference if you guys think this is an OData specific issue.
From the API tester tool in our platform (does what postman does using ajax calls) this is what the .Net 4.6 version does for comparison and ultimately what I would expect form the same code in netcore ...
... Interestingly i notice that there is a response coming back but it appears to be incomplete ...
{"@odata.context":"https://mydomain/Core/$metadata#packages","value":[{"Id":"00000000-0000-0000-0000-000000000000","Name":"Roles"
... It appears to be cutting the response short for some reason (presumably due to some sort of serialization failure and the frameworks resulting behavior from the framework must then be to just end the response.
Is there any way I can catch internal exceptions / issues in the framework to help with this?
I do already have this in my startup ...
app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
var ex = context.Features.Get<IExceptionHandlerPathFeature>();
log.Error(ex.Error.Message + "\n" + ex.Error.StackTrace);
context.Response.StatusCode = ex.Error.GetType() == typeof(SecurityException) ? 401 : 500;
context.Response.ContentType = "application/json";
await context.Response.WriteAsync("{ \"error\": \"" + ex.Error.Message.Replace("\"", "\'") + "\" }");
});
});
... but it's not logging anything which suggests that this might be intended behavior for some reason.
Further information ....
- I have discounted it being a client issue as this happens from multiple browsers.
- I have discounted this as being an EF / ORM issue as the data is computed and contains no actual entities managed by the EF context (although the data has come from EF).
- The code runs completely right through to beyond the Ok() call in the controller which returns a Package[] (see type data above).