Получение исключения во время работы на сервере после публикации, но оно работает в локальной системе с публикацией или без нее. Я застрял в ней на один день, пожалуйста, помогите для работы вокруг. Он работает нормально на локальной машине разработки, но выдает исключение после публикации и развертывания на сервере
У меня есть попытки изменения конструктора, изменения объекта базы данных с использованием блока «using» и т. Д.
Вот трассировка стека
[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; }
}
}