I\'m using Web.api and Unity and I am getting the following error when trying to open the default \"help\" area:
[InvalidOperationException: The type String cann
As your code sample, I'm assuming you are on a Controller and not a API Controller (from web api).
Your api controller has a dependency on the constructor from HttpConfiguration
. The container problably does not have this definition for this type and consequently does not know how to solve it and the string
on the error message should come from this type as a dependency. I recommend you use the GlobalConfiguration
static class and access the Configuration
property to get a HttpConfiguration
instance. You could abstract it in a property, for sample:
// include this namespace
using System.Web.Http;
public class HelpController : Controller
{
// remove the constructors...
// property
protected static HttpConfiguration Configuration
{
get { return GlobalConfiguration.Configuration; }
}
public ActionResult Index()
{
return View(this.Configuration.Services.GetApiExplorer().ApiDescriptions);
}
public ActionResult Api(string apiId)
{
if (!String.IsNullOrEmpty(apiId))
{
HelpPageApiModel apiModel = this.Configuration.GetHelpPageApiModel(apiId);
if (apiModel != null)
{
return View(apiModel);
}
}
return View("Error");
}
}
Now, if you are on a Api Controller, you just can access directly the this.Configuration
property that is already on the ApiController (base class for Api controllers) and get a instance of HttpConfiguration
.