开发者

System.MissingMethodException: No parameterless constructor defined for this object

I have a ELMAH controller factorym these steps for using ELMAH makes it so I dont have to mark each method in the controllers. that file is telling me I dont have a parameterless constructor while I clearly do

PriceListController

public partial class PriceListController : Controller
{

    public PriceListController()
    {
    }


    [CanonicalUrlAttribute("PriceList")]
    [CompressionFilter(Order = 1)]
    [CacheFilter(Duration = 120, Order = 2)]
    public virtual ActionResult Index()
    {
        GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities();
        var viewModel = new PriceListViewModel() { PriceListAnimals = context.GetAnimalListForPriceList() };
        return View(viewModel);
    }


    [CompressionFilter(Order = 1)]
    [CacheFilter(Duration = 120, Order = 2)]
    public virtual ActionResult List(string animal)
    {
        GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities();

        var viewModel = new PriceListIndexViewModel() { AnimalPrices = context.GetPriceListByAnimal(animal) };
        return View(viewModel);
    }

}

ELMAHControllerFactory.cs

// <summary>
/// This custom controller factory injects a custom attribute 
/// on every action that is invoked by the controller
/// </summary>
public class ELMAHControllerFactory : DefaultControllerFactory
{
    /// <summary>
    /// Injects a custom attribute 
    /// on every action that is invoked by the controller
    /// </summary>
    /// <param name="requestContext">The request context</param>
    /// <param name="controllerName">The name of the controller</param>
    /// <returns>An instance of a controller</returns>
    public override IController CreateController(RequestContext requestContext, string controllerName)
    {
        var controller = base.Creat开发者_如何学GoeController(requestContext, controllerName);

        var c = controller as Controller;

        if (c != null)
            c.ActionInvoker = new ELMAHActionInvoker(new HandleErrorWithELMAHAttribute());

        return controller;
    }
}

I may be misunderstanding but I thought there was a parameterless constructor there, was I wrong?


This is resolved, I deleted the parameterless constructor and made a new one and that error went away.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜