-1

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);
    }
BenMorel
  • 34,448
  • 50
  • 182
  • 322
62071072SP
  • 1,963
  • 2
  • 19
  • 38
  • Please show us an error or something. How can we possible know what the problem is with "but there is an error"? We can throw out random suggestions but that won't help unless you tell us what the error is. – Simon Whitehead Aug 19 '13 at 22:44
  • @SimonWhitehead I have set custom errors off in config and I am getting error. Please see my edited post – 62071072SP Aug 19 '13 at 22:45
  • Your code has a `null` object. Show us your `AccountController`'s `Register()` action method and we can help you diagnose it. It is probably data related.. your local data is as expected but your live database is lacking some data that you are just expecting to be there. – Simon Whitehead Aug 19 '13 at 22:47
  • @SimonWhitehead Please check , I updated my action – 62071072SP Aug 19 '13 at 22:51
  • It is probably because the error is quite clear. `NullReferenceException` is very descriptive.. something is `null`. It even tells you what method it happened in (that's how I knew.. from your Stack Trace). – Simon Whitehead Aug 19 '13 at 22:58

1 Answers1

4

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
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
  • 1
    Yes you are right I have created new table Corporations which doesnt have any data in live and after inserting data I am getting different error : Please see my edited post – 62071072SP Aug 19 '13 at 22:58