我有同样的问题,我不使用 Glimpse,我解决了这样的问题:
在ProjectName\Areas\HelpPage\Controllers\HelpController.cs
文件注释中,构造函数因为不被称为隐式构造函数 public HelpController() : this(GlobalConfiguration.Configuration)
,默认被称为带有参数的构造函数, public HelpController(HttpConfiguration config)
并且该Configuration
属性的初始化是不正确的。你可以像这样解决这个问题:
解决方案 1:
注释/删除构造函数。
public class HelpController : Controller
{
private const string ErrorViewName = "Error";
// public HelpController()
// : this(GlobalConfiguration.Configuration)
// {
// }
// public HelpController(HttpConfiguration config)
// {
// Configuration = config;
// }
/// <summary>
/// GlobalConfiguration By default
/// </summary>
protected static HttpConfiguration Configuration
{
get { return GlobalConfiguration.Configuration; }
}
public ActionResult Index()
{
ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
}
....
解决方案2:
通过添加该属性[InjectionConstructor]注入默认构造函数。
public class HelpController : Controller
{
private const string ErrorViewName = "Error";
[InjectionConstructor]
public HelpController()
: this(GlobalConfiguration.Configuration)
{
}
public HelpController(HttpConfiguration config)
{
Configuration = config;
}
/// <summary>
/// GlobalConfiguration By default
/// </summary>
protected static HttpConfiguration Configuration { get; private set; }
....
并且问题解决了。