Search code examples
asp.net-mvcasp.net-mvc-4deploymentwindows-server-2008msdeploy

Problems with deploying MVC 4 app on Windows Server 2008


I have deployed this MVC app on my localhost(on my machine running windows 8) and it runs as expected. The only difference between my installation folder and the one which is on the server, is the connection string. But when I try to deploy it on the server machine(Windows Server 2008) I get this strange error :

[NullReferenceException: Object reference not set to an instance of an object.] PicknikMVC.ViewModels.ApplicationViewModel..ctor(Application app) in c:\Builds\workspace\Picknik\AppStoreService\target\checkout\AppStoreService\PicknikMVC\ViewModels\Application\ApplicationViewModel.cs:23 PicknikMVC.Controllers.Application.ShowController.Execute(String appid) in c:\Builds\workspace\Picknik\AppStoreService\target\checkout\AppStoreService\PicknikMVC\Controllers\Application\ShowController.cs:59 lambda_method(Closure , ControllerBase , Object[] ) +126 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters)+247 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +38 System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +119 System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +452 System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +31 System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +230 System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

The code in the app where this happens is basically instantiating a new object of particular class with some information from the database. Do you see any obvious problem? Could it be a problem with the connection string or it is something else?

AppViewModel:

 public class ApplicationViewModel
{
    public int App_ID { get; set; }

    public string Title { get; set; }

    public string Developer { get; set; }

    public string DeveloperURL { get; set; }

    public bool IsImportant { get; set; }

    public IEnumerable<ScreenshotPairViewModel> Screenshots { get; set; }

    public ApplicationViewModel(PicknikData.Application app)
    {
        App_ID = app.App_ID;
        Title = app.Title;
        Developer = app.Developer;
        DeveloperURL = app.DeveloperURL;
        if (app.IsImportant.HasValue) 
        {
            IsImportant = app.IsImportant.Value;
        }

        Screenshots = app.ScreenshotURLs.Select(p => new ScreenshotPairViewModel(p.Screenshot_URL,p.FK_Device)).ToList();

    }
}

and the code for the controller:

 viewModel.Application = new ApplicationViewModel(app);

Solution

  • It is hard to tell from the info provided, but I'll have a bash at helping.

    If the connection string is different, I assume the data might be too.

    When you see object not set, it is usually something not instantiated in the code. In this case though, it could be the data. Assuming everything is instantiated somewhere, it is possible there are no ScreenshotURLs? The error message details a lambda error, so I assume the it relates to the select statement.