在服务器上发布后运行但在本地计算机上正常运行时,在mvc 5中加载视图时出现异常

穆罕默德

发布后在服务器上运行时发生异常,但无论发布与否,它都在本地系统上运行。我在其中停留了一天,请帮忙解决。它在本地开发计算机上工作正常,但是在服务器中发布和部署后引发异常

我尝试了构造函数更改,“使用”块等数据库对象更改

这是堆栈跟踪

[NullReferenceException: Object reference not set to an instance of an object.]
   RAMSWeb.Controllers.GTLMTVariableProcessController..ctor() +101

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +139
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +105
   System.Activator.CreateInstance(Type type) +12
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +75

[InvalidOperationException: An error occurred when trying to create a controller of type 'RAMSWeb.Controllers.GTLMTVariableProcessController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +242
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +103
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +263
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +77
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1020
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128

控制者



  [HttpGet]
        public ActionResult CallEmployeesGT()
        {
            return View(new GTLMTCallEmployesVM());
        }


模型:

public class GTLMTCallEmployesVM
{
        private ApplicationDbContext db;

        System.Security.Principal.IPrincipal user = HttpContext.Current.User;

        public GTLMTCallEmployesVM()
        {
            db = new ApplicationDbContext();

        } 

        [Required]
        [Display(Name = "Month")]
        public string TransactionMonth { get; set; }

        [Required]
        [Display(Name = "Year")]
        public string TransactionYear { get; set; }


        [Required]
        [Display(Name = "To Date")]
        public DateTime SalaryToDate { get; set; }


        [Required]
        [Display(Name = "From Date")]
        public DateTime SalaryFromDate { get; set; }


        [Required]
        [Display(Name = "Distributor")]
        public string BranchCode { get; set; }



        private SelectList _branchSelectListGT { get; set; }
        public SelectList BranchSelectListGT
        {
            get
            {
                if (_branchSelectListGT != null) return _branchSelectListGT;
                else
                {
                    if (user.IsInRole(constant.Roles.SuperAdmin) || user.IsInRole(constant.Roles.Admin))
                    {
                        return new SelectList(db.Branches.Where(x => x.DistributorType == SalaryModuleHelper.DistributorType.GT && x.DisableDate == null).ToList().Select(y => new BranchSelectListVM { BranchCode = y.BranchCode, BranchName = y.Name + "(" + y.BranchCode + ") " + y.DistributorType }).ToList(), "BranchCode", "BranchName");
                    }
                    else
                    {
                        var loggedInUserBranches = constant.GlobalHelper.GetBranchIds(user.Identity.GetUserId());

                        return new SelectList(db.Branches.Where(x => loggedInUserBranches.Any(y => y.Trim() == x.BranchCode.Trim()) && x.DistributorType == SalaryModuleHelper.DistributorType.GT && x.DisableDate == null).Select(x => new BranchSelectListVM { BranchCode = x.BranchCode, BranchName = x.Name + " (" + x.BranchCode + ") "+ x.DistributorType }).ToList(), "BranchCode", "BranchName");

                    }
                }
            }
            set { _branchSelectListGT = value; }
        }
}
姆塔里克

恕我直言,异常告诉您模型中的属性之一为空。我认为数据库连接有问题。您检查连接字符串了吗?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Mac:如何从其他计算机远程访问在Docker容器中运行的服务器?

如何在Node.js中获得服务器正常运行时间?

第二次运行VBA代码时,出现“运行时错误462:远程服务器计算机不存在或不可用”

Openshift上的Node.js出现错误400,但在本地计算机上正常运行

Docker中的Wildfly群-启动http服务器时出现异常

从本地计算机上的服务器克隆git存储库时出错

使用Python,如何将多个文件从FTP服务器上的子目录下载到本地计算机上的所需目录中?

Postgres select查询在使用JDBC时运行缓慢,但在同一服务器上的PSQL中运行时运行很快

在hda应用程序中获取远程服务器正常运行时间

当应用程序在多台计算机上运行时,在play框架中处理缓存

将ls命令的结果保存在本地计算机上的远程sftp服务器中

在本地计算机上部署Web服务工作,但在另一台计算机上抛出运行时错误

在Azure sql服务器上运行脚本但在本地sql服务器上正常运行时出现错误

在本地和服务器上运行时,python中的datetime.now不同

如何捕获远程Linux服务器上的实时流量,以及如何在本地Windows计算机上的Wireshark中查看实时流量?

如果计算机正常运行时间大于5分钟,则需要帮助进行bash检查

在VBA中打开Excel文件:运行时错误'462':远程服务器计算机不存在或不可用

在计算机上运行apache2 httpd Web服务器时出错

从我的计算机在主机服务器中运行脚本并关闭计算机

MVC5 URL不匹配可在localhost上运行,但不能在远程计算机上运行

加载插件管理器时出现异常

从 IOS 中的自定义表视图控制器中的响应加载数据时出现异常错误

我可以在 xampp (localhost) 中运行我的项目,但即使在配置后尝试在另一台计算机上运行时也无法运行

安装 Microsoft.Azure.SignalR.AspNet 会导致方法在部署到服务器时未实现运行时错误,但在 Visual Studio 2017 上运行良好

通过 jmeter 中的 Pepperbox 采样器连接 kafka 服务器时出现异常

计算 PSNR 时出现异常

PHP 中的 zipArcvhive 无法在服务器上运行,但在本地主机上运行并提取文件

SVM 预测在我的计算机上运行良好,但在 R Connect 中运行不正常

Selenium WebDriverManager - 在 Linux 服务器上运行时出现异常