samedi 31 octobre 2015

Activator.CreateInstance can't find the constructor

I got an error in BaseRenderModel<TBaseEntity> class that says Constructor on type 'Jahan.Nuts.Model.UModel.HomePage' not found.

I double checked the code and read some solutions in Internet about it but I couldn't solve my problem. I've used Umbraco 7.3 (ASP.NET MVC) at my project

How can I solve this problem?

namespace Jahan.Nuts.Model.UModel.URenderModel
{
public class BaseRenderModel<TBaseEntity> : RenderModel where TBaseEntity : BaseEntity
{

    public TBaseEntity Model { get; set; }
    public BaseRenderModel(IPublishedContent content, CultureInfo culture) : base(content, culture)
    {
        object args = new object[] { content, culture };
        Model = (TBaseEntity)Activator.CreateInstance(typeof(TBaseEntity), args); //Constructor on type 'Jahan.Nuts.Model.UModel.HomePage' not found.
    }
}
}

Class BaseEntity:

public class BaseEntity
{
   public BaseEntity()
    {

    }
    public BaseEntity(IPublishedContent content, CultureInfo culture)
    {
       // some codes
    }
    public BaseEntity(IPublishedContent content)
    {
       // some codes
    }
}

Class HomePage:

public class HomePage : BaseEntity
{
    public List<Photo> PhotoList { get; set; }

    public HomePage(IPublishedContent content, CultureInfo culture) : base(content, culture)
    {
        Initialize(content, culture);
    }
    public HomePage(IPublishedContent content) : base(content)
    {
        Initialize(content, null);
    }
    protected HomePage()
    {
    }
}

Class HomePageController:

public class HomePageController : RenderMvcController
 {
    public override ActionResult Index(RenderModel model)
    {
        BaseRenderModel<HomePage> instance = new BaseRenderModel<HomePage>(model.Content, model.CurrentCulture);
        return base.Index(instance);
    }
}





Aucun commentaire:

Enregistrer un commentaire