我有一个工作的 Visual Studio 项目,我想用 Mono 和 MonoDevelop 运行 Mac。该项目是一个带有 Ninject MVC 的 ASP.NET MVC 3 应用程序,它基本上在控制器上注入了一些接口实现。
将所有 ASP.NET MVC dll 和 Ninject 依赖项添加到项目中后,编译成功。但是当我去运行它时,我遇到了错误:
未找到类型 WebActivatorTest.Controllers.HomeController 的默认构造函数。
我的控制器有以下代码:
public class HomeController : Controller
{
INotifier _notifier;
public HomeController(INotifier notifier_)
{
_notifier = notifier_;
}
public ActionResult Index()
{
ViewBag.Name = _notifier.Person();
return View();
}
}
我不想有一个空的构造函数,因为我现在有一个 AppStart 代码注册我的接口:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<WebActivatorTest.Models.INotifier>().To<WebActivatorTest.Models.Notifier>();
}
此代码在 Windows/Visual Studio 上完美运行,但在 Mono 上无法运行。有人可以帮我吗?
完整的错误是:
Server Error in '/' Application
Default constructor not found for type WebActivatorTest.Controllers.HomeController.
Description: HTTP 500. Error processing request.
Stack Trace:
System.MissingMethodException: Default constructor not found for type WebActivatorTest.Controllers.HomeController.
at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at System.Web.Mvc.DefaultControllerFactory+DefaultControllerActivator.Create (System.Web.Routing.RequestContext requestContext, System.Type controllerType) [0x00000] in <filename unknown>:0
Version information: Mono Runtime Version: 2.10.9 (tarball Tue Mar 20 15:31:37 EDT 2012); ASP.NET Version: 4.0.30319.1