asp.net - mscorlib.dll 中出现“System.AggregateException”类型的异常,但未在用户代码中处理
问题描述
您好,我正在尝试使用 rest web 服务并在 chtml 中公开它,但是当我启动我的应用程序时我不断收到这个错误,我不明白它。是因为缺少库或依赖项吗?
缺勤控制器:
using ProjectWeb.Models;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Mvc;
namespace ProjectWeb.Controllers
{
public class AbsenceController : Controller
{
// GET: Absence
public ActionResult Index()
{
HttpClient Client = new System.Net.Http.HttpClient();
Client.BaseAddress = new Uri("http://localhost:18080/PiDev-web/rest/absence/");
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = Client.GetAsync("all").Result;
if (response.IsSuccessStatusCode)
{
ViewBag.result = response.Content.ReadAsAsync<IEnumerable<Absence>>().Result;
///ViewBag.result1 = response.Content.ReadAsStringAsync().Result;
}
else
{
ViewBag.result = "error";
}
return View("index");
}
// GET: Absence/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: Absence/Create
public ActionResult Create()
{
return View();
}
// POST: Absence/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Absence/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: Absence/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Absence/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: Absence/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
我的 index.chtml:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>index</title>
</head>
<body>
<br />
<h3>
@Html.ActionLink("Ajouter Absence ", "Create")
</h3>
<hr />
<table class="table">
<tr>
<th>ID</th>
<th>Nom</th>
<th>Action</th>
</tr>
@foreach (var h in ViewBag.result)
{
<tr>
<td>@h.idAbsence</td>
<td>@h.cause</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = h.idAbsence }) |
@Html.ActionLink("Details", "Details", new { id = h.idAbsence }) |
@Html.ActionLink("Delete", "Delete", new { id = h.idAbsence })
</td>
</tr>
}
</table>
</body>
</html>
当我通过按浏览器上的视图启动它时,我收到此错误 ,请在此处输入图像描述
当我按下它时,错误是由以下原因引起的:
ViewBag.result =response.Content.ReadAsAsync<IEnumerable<Absence().Result;
如果您熟悉此错误,请帮助我
解决方案
在您的情况下, AggregateException 可能意味着任务引发了异常。您可以在调试选项下打开“Break On All Exceptions”,然后再次运行以找出原始异常。
哦,取消选择“仅启用我的代码”
推荐阅读
- python - Neuropy 库 TypeError:__init__() 缺少 1 个必需的位置参数:“端口”
- python - Athena 为镶木地板文件中的时间戳字段返回错误值
- swift - Realm Swift:如何将不同的 Realm 对象映射到一个符合相同协议的 List<>
- python - 如何在 Python 中更好地在它们之间分配可靠的变量?
- selenium - 找不到语言引擎:使用组运行 TestNG 时的 beanshell
- c++ - 如何使用 C++11 声明静态查找表
- python - 如何在 Altair 图中展开所有图例条目
- javascript - 如何创建一个将随机字符串(来自数组)分配给某个变量的函数?
- c# - 如何在运行时统一旋转游戏对象
- mysql - MySQL:尝试运行 CUBE 查询 -> sql 语法错误 | 限制 0,25