类型'System.Collections.Generic.ISet [Model.InputFieldVisibility]没有默认的构造函数。参数名称:type

时间:2018-12-03 14:50:17

标签: asp.net-web-api nhibernate asp.net-core-2.1

我正在使用Asp.net core 2.1,在我的本地主机上一切正常,但是在部署后出现此错误: 类型'System.Collections.Generic.ISet'1 [Model.InputFieldVisibility]'没有默认的构造函数。参数名称:type。这是我的控制器:

public class InputFieldVisibilityController : ControllerBase
{
    private readonly UserManagementProvider _userManagementProvider;
    private readonly Log _log;
    private readonly SharedLocalizer _sharedLocalizer;
    public InputFieldVisibilityController(UserManagementProvider userManagementProvider, 
                                Log log, SharedLocalizer sharedLocalizer)
    {
        this._userManagementProvider = userManagementProvider;
        this._sharedLocalizer = sharedLocalizer;
        this._log = log;
    }
    [HttpGet("getAll/{idUser}/{entity}")]
    public ISet<InputFieldVisibility> getAll(string idUser, string entity)
    {
        ICriteria criteria = ((IStatelessSession)HttpContext.Items["statelessSession"])
                                .CreateCriteria(typeof(InputFieldVisibility));
        criteria.CreateAlias("user", "user", NHibernate.SqlCommand.JoinType.LeftOuterJoin);
        criteria.Add(Restrictions.Eq("user.id", int.Parse(idUser)));


        criteria.Add(Restrictions.Eq("entity", 
                                    (InputFieldVisibility.Entity)int.Parse(entity)));
        ISet<InputFieldVisibility> inputFieldVisibilities = 
                new HashSet<InputFieldVisibility>(criteria.List<InputFieldVisibility>());

        inputFieldVisibilities.Select(item => item.user.societies = null).ToList();
        inputFieldVisibilities.Select(item => item.user.inputFieldVisibilites = null)
                .ToList();
        return inputFieldVisibilities;
    }
    [HttpPost]
    [Route("create/{idUser}/{entity}")]
    public void create(int idUser, string entity, 
                        ISet<InputFieldVisibility> inputFieldVisibilities)
    {
        _log.LogDebug("1111111111", HttpContext);
        string jwToken = Request.Headers["Authorization"].ToArray()[0].Split(' ')[1];
        UserManagement userManagement = this._userManagementProvider
                                    .userManagement
                                    .Where(item => item.token == jwToken).ToList()[0];
        if (userManagement.user.type != Model.User.Type.ADMINISTRATOR)
        {
            throw new MyException(
                        _sharedLocalizer
                                .GetLocalizedString("ProhibitedFunctionality"), 
                        System.Net.HttpStatusCode.Unauthorized);
        }

        User user = ((IStatelessSession)HttpContext.Items["statelessSession"])
                    .CreateCriteria(typeof(User))
                    .Add(Restrictions.Eq("id",idUser))
                    .UniqueResult<User>();
        if (user == null) 
        {
            throw new MyException(_sharedLocalizer.GetLocalizedString("EmptyList"),
                                    System.Net.HttpStatusCode.Unauthorized);
        }

        // il faut supprimer tous les anciens tuples avant d'insérer les nvx
        ICriteria criteria = ((IStatelessSession)HttpContext.Items["statelessSession"])
                                .CreateCriteria(typeof(InputFieldVisibility));
        criteria.CreateAlias("user", "user", 
                            NHibernate.SqlCommand.JoinType.LeftOuterJoin);
        criteria.Add(Restrictions.Eq("user.id", user.id));
        criteria.Add(Restrictions.Eq("entity", 
                                    (InputFieldVisibility.Entity)int.Parse(entity)));
        ISet<InputFieldVisibility> oldInputFieldVisibilities = 
                        new HashSet<InputFieldVisibility>(criteria.List<InputFieldVisibility>());


        _log.LogDebug("22222222222", HttpContext);

        foreach (InputFieldVisibility inputFieldVisibility in oldInputFieldVisibilities) {
            _log.LogDebug("----------", HttpContext);
            ((NHibernate.ISession)HttpContext
                    .Items["sessionWithState"]).Delete(inputFieldVisibility);
            ((NHibernate.ISession)HttpContext
                    .Items["sessionWithState"]).Flush();
            ((NHibernate.ISession)HttpContext
                    .Items["sessionWithState"]).Evict(inputFieldVisibility);
        }
        _log.LogDebug("333333333333333", HttpContext);

        // Insert
        foreach (InputFieldVisibility inputFieldVisibility in inputFieldVisibilities) {
            _log.LogDebug("***********", HttpContext);
            inputFieldVisibility.user = user;
            ((NHibernate.ISession)HttpContext
                    .Items["sessionWithState"]).Save(inputFieldVisibility);
            ((NHibernate.ISession)HttpContext
                    .Items["sessionWithState"]).Flush();
            ((NHibernate.ISession)HttpContext
                    .Items["sessionWithState"]).Evict(inputFieldVisibility);
        }
        _log.LogDebug("444444444444", HttpContext);

    }
}

有人对此问题背后的原因有任何想法吗? 谢谢。

0 个答案:

没有答案