I was hoping I could get an extra set of eyes on this issue I'm facing, as I do not know how to solve it.
I'm getting 3 different exceptions...
Let me provide some background & context. I am working on a customer ticketing system, and it was working just fine... right up until I made some slight modifications. Those modifications basically involved me "including" the TicketComments collection as it is referenced within the Ticket model. Allow me to show you those changes...
I basically am trying to add support to include the "number of ticket comments" as a data field I can display in a table of customer Tickets.
namespace SupportSite.WebServices
{
public class Ticket
{
[Key]
public int ID { get; set; }
public string Description { get; set; }
public string Priority { get; set; }
public DateTime RequestedOnDate { get; set; }
public string Status { get; set; }
public ICollection<TicketComment> TicketComments { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public int? NumTicketComments => TicketComments?.Count();
}
}
namespace SupportSite.WebServices.Controllers
{
public class TicketController : Controller
{
private readonly SupportContext _context;
public TicketController(SupportContext context)
{
_context = context;
}
public ActionResult List()
{
//var tickets = _context.Tickets.ToList(); //I've changed this line to...
var tickets = _context.Tickets.Include(cls => cls.TicketComments).ToList(); //this one, to include the TicketComments, so I can count them and set NumTicketComments
return Json(tickets);
}
//... (yawn)...
}
}
But this broke the damn thing and I don't know what to do about it. I'm in the dark. I'm obviously missing something here and I don't know what that missing thing is. Can anybody shed some light on this for me please?
Let me also show you the calling function/how it gets called. I've set breakpoints on my code and I successfully get the data from the database. As in... the "tickets" variable you can see above successfully returns the data. It looks good. As you can see...
In order to build out the page to display the tickets/when loading the "Ticket/List" page... the browser will issue a call to the following code:
namespace SupportSite.Controllers
{
public class TicketController : Controller
{
public IActionResult Index()
{
var tickets = new TicketAPI().List(); // ### THIS IS THE LINE THAT CALLS THE API INITIALLY
var page = new Page();
page.Components.Add(new TicketListComponent(tickets));
return Json(page);
}
public IActionResult Frame()
{
return View();
}
}
}
that calls...
namespace SupportSite.API.APIs
{
public class TicketAPI : BaseWSAPI
{
public List<TicketFormatted> List()
{
return HttpClient.PostJsonEncoded<List<TicketFormatted>>(GetUrl(nameof(List)));
}
}
}
which calls...
public TReturn PostJsonEncoded<TReturn>(string url)
{
return
HandleResponse<TReturn(HttpClient.SendAsync(ApplyHeaders(newHttpRequestMessage(HttpMethod.Post, url))),
url);
}
The error occurs here though when the HttpResponse returns and gets handled ....
The exception reads as such:
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at SupportSite.API.HttpClientUtility.HandleResponse[U](Task`1 response, String url) in C:\Users\jsnow\Source\Repos\Assessment-jsnow\SupportSite\SupportSite.API\BaseWSAPI.cs:line 95
at SupportSite.API.HttpClientUtility.PostJsonEncoded[TReturn](String url) in C:\Users\jsnow\Source\Repos\Assessment-jsnow\SupportSite\SupportSite.API\BaseWSAPI.cs:line 69
at SupportSite.API.APIs.TicketAPI.List() in C:\Users\jsnow\Source\Repos\Assessment-jsnow\SupportSite\SupportSite.API\APIs\TicketAPI.cs:line 12
at SupportSite.Controllers.TicketController.Index() in C:\Users\jsnow\Source\Repos\Assessment-jsnow\SupportSite\SupportSite\Controllers\TicketController.cs:line 15
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
HttpRequestException: Error while copying content to a stream.
Inner Exception 2:
IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Inner Exception 3:
SocketException: An existing connection was forcibly closed by the remote host
What is the root of this issue and how might I solve it? Is there a particular technique or pattern I could apply to solve this? I'm not sure what I'm missing but I'm obviously missing something here. Any help on this would be greatly appreciated. I'm stuck. Thank you in advance.
User contributions licensed under CC BY-SA 3.0