Reputation: 11875
I have a signup page. it works in my local computer, but after I deployed to the production. Kept getting following error message
Server Error in '/' Application.
Error1: Value cannot be null.
Parameter name: view
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: Error1: Value cannot be null.
Parameter name: view
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[Exception: Error1: Value cannot be null.
Parameter name: view]
Smoothie.Web.Controllers.AccountController.Signup(UserRegisterViewModel user, String returnUrl) +662
lambda_method(Closure , ControllerBase , Object[] ) +149
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +181
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
System.Web.Mvc.Controller.ExecuteCore() +105
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Here's my code, I spent whole day to debug it, still no luck.
//[ChildActionOnly]
public virtual ActionResult Signup(string returnUrl)
{
return PartialView(MVC.Account.Views._Register, new UserRegisterViewModel());
//return PartialView("_Register", new UserRegisterViewModel());
}
[HttpPost]
[ValidateAntiForgeryToken]
public virtual ActionResult Signup(UserRegisterViewModel user, string returnUrl)
{
try
{
if (ModelState.IsValid)
{
var newUser = _mappingService.Map<UserRegisterViewModel, User>(user);
if (newUser == null)
{
throw new Exception("newUser cannot be null");
}
var confirmation = _userService.AddUser(newUser, AccountType.Smoothie);
if (confirmation.WasSuccessful)
{
var userData = _mappingService.Map<User, UserDataDto>(confirmation.Value);
if (userData == null)
{
throw new Exception("userData cannot be null");
}
_authenticationService.SetAuthCookie(Response, userData.DisplayName, false, userData);
Utilities.SendEmail(ConfigurationManager.AppSettings["EmailReply"],
new List<string> {userData.Email}, "Welcome to putastrawinit.com",
GetWelcomeEmail());
var redirectUrl = "/home";
if (returnUrl != null && Url.IsLocalUrl(returnUrl))
{
redirectUrl = returnUrl;
}
return Json(new {Success = true, RedirectUrl = redirectUrl});
//return RedirectToAction("Index", "Home", null);
}
ModelState.AddModelError("", confirmation.Message);
}
}
catch (Exception e)
{
throw new Exception("Error1: " + e.Message);
}
var errors = from value in ModelState.Values
from error in value.Errors
select new { error.ErrorMessage };
//throw new Exception("Errors: " + errors.ToString());
return Json(new { Success = false, ErrorMessages = errors });
}
sign up view page.
@model Smoothie.Domain.ViewModels.UserRegisterViewModel
@using (Ajax.BeginForm("Signup", "Account", new AjaxOptions { OnSuccess = "onSignupSuccess", OnFailure = "onSignupFailure" }))
{
@Html.AntiForgeryToken()
@Html.Hidden("returnUrl", null, new { value = @Request.QueryString["returnUrl"] })
<div class="signupForm">
<div>@Html.ValidationSummary("", new { @id = "signupSummary" })</div>
<div class="row">
<label for="Email">
Display Name:</label>
@Html.EditorFor(m => m.DisplayName)
</div>
<div class="row">
<label for="Email">
Email Address:</label>
@Html.TextBoxFor(m => m.Email, new {@class = "text-box", autocomplete = "off" })
</div>
<div class="row">
<label for="Password">
Password:</label>
@Html.TextBox("Password", null, new { @class = "registerPassword text-box", type = "password", autocomplete = "off" })
</div>
<div class="row">
<label>
</label>
<div class="registerChecker">
</div>
</div>
<div class="row">
<label>
</label>
<input type="image" src="@Links.Content.images.btn_sign_up_png" style="width: 91px; height: 33px;" value="Create" />
</div>
</div>
}
this is the ViewModel.
using System.ComponentModel.DataAnnotations;
namespace Smoothie.Domain.ViewModels
{
public class UserRegisterViewModel
{
[Required(ErrorMessage = "Email is required")]
[StringLength(255, ErrorMessage = "Email must be 50 characters or fewer")]
[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Your Email address is invalid")]
public string Email { get; set; }
[Required(ErrorMessage = "Display name is required")]
[StringLength(25, MinimumLength = 2, ErrorMessage = "Display name must be between 2 and 25 characters")]
public string DisplayName { get; set; }
[DataType(DataType.Password)]
[Required(ErrorMessage = "Password is required")]
[StringLength(25, MinimumLength = 8, ErrorMessage = "Password must be between 8 and 25 characters")]
public string Password { get; set; }
}
}
this is the new stack trace after I removed try catch from the code.
Value cannot be null.
Parameter name: view
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: view
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: view]
System.Web.Mvc.ViewContext..ctor(ControllerContext controllerContext, IView view, ViewDataDictionary viewData, TempDataDictionary tempData, TextWriter writer) +205
Smoothie.Web.Controllers.AccountController.GetWelcomeEmail() +178
Smoothie.Web.Controllers.AccountController.Signup(UserRegisterViewModel user) +288
lambda_method(Closure , ControllerBase , Object[] ) +106
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +181
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
System.Web.Mvc.Controller.ExecuteCore() +105
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Upvotes: 0
Views: 2987
Reputation: 15924
Based on the latest call stack, it looks like the view is missing from GetWelcomeEmail()
which is causing view
to be null in the ViewContexts constructor.
Upvotes: 2