Pregunta

This is the first time I am deploying MVC web application in Amazon S3 server. And website is been loaded in browser but when I click on register button it is throwing error. I can see only difference is My application is named as reporting.e-tale.co.uk and Domain is set up as dashboard.e-tale.co.uk, so I made a folder in live as dashboard.e-tale.co.uk and copied my files. It is working fine in local dont know the reason why it is throwing error.

Please correct me If I am doing any thing wrong. I am not sure what details to provide. I will provide you more details if it is difficult to suggest solution. Thanks

Server Error in '/' Application.

Object reference not set to an instance of an object.

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.NullReferenceException: Object reference not set to an instance of an object.

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:

[NullReferenceException: Object reference not set to an instance of an object.] reporting.e_tale.co.uk.Controllers.AccountController.Register() +255 lambda_method(Closure , ControllerBase , Object[] ) +78 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +263 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +38 System.Web.Mvc.<>c_DisplayClass15.b_12() +128 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +826106 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +826106 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +826106 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825328 System.Web.Mvc.Controller.ExecuteCore() +159 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335 System.Web.Mvc.<>c_DisplayClassb.b_5() +62 System.Web.Mvc.Async.<>c_DisplayClass1.b_0() +20 System.Web.Mvc.<>c_DisplayClasse.b_d() +54 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1008

Account controller (Register)

     /// <summary>
    /// GET: /Account/Register
    /// Action account Register.
    /// </summary>
    /// <returns></returns>
    [AcceptVerbs(HttpVerbs.Get)]
     public ActionResult Register()
    {
        var myViewData = new RegisterForm
        {
            Person = new Person
            {
                CreatedAt = DateTime.Now,
                AppellationId =
                    _appellationRepository.GetAppellationByDescription(
                        "Mr").Id,
                CountryId =
                    _countryRepository.GetCountryByName(
                        "United Kingdom").Id,
                CorporationId = _corporationRepository.GetCorporationByName(
                "Samsung").Id
                //ManufacturerId = _manufacturerRepository.GetManufacturerByName(
                //"Samsung").Id
            },
            User =
                new User
                {
                    CreatedAt = DateTime.Now,
                    Guid = Guid.NewGuid().ToString("N")
                }
        };

        myViewData.Appellations = new SelectList(_appellationRepository.GetAllAppellations().ToList(), "Id",
                                                 "Description", myViewData.Person.AppellationId);
        myViewData.Countries = new SelectList(_countryRepository.GetAllCountries().ToList(), "Id", "Name",
                                              myViewData.Person.CountryId);
        myViewData.Corporations = new SelectList(_corporationRepository.GetAllcorporations().ToList(), "Id",
                                                "Description", myViewData.Person.CorporationId);
        //myViewData.Manufacturers = new SelectList(_manufacturerRepository.GetAllManufacturers().ToList(),"Id",
        //    "Description",myViewData.Person.ManufacturerId);
        myViewData.PasswordLength = MembershipService.MinPasswordLength;

        return View(myViewData);
    }
¿Fue útil?

Solución

Your code is not very defensive.. hence your issue.

There is a null object in your AccountController's Register() method.. what could that be?

Any of these:

_appellationRepository.GetAppellationByDescription("Mr")
_countryRepository.GetCountryByName("United Kingdom")
_corporationRepository.GetCorporationByName("Samsung")

Check your data, and check that your repositories are actually returning data. You can't check a property on a null object (which you are doing by having .Id after each one of the above calls). As I said in the comments.. it is probably because your live database does not contain all of the data that your local database contains. Make sure they match 1-to-1 and while you're there... put some defence mechanisms in place! E.g:

var country = _countryRepository.GetCountryByName("United Kingdom");

if (country == null) 
    // Log the error or give a more descriptive error
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top