0

我已经在我的本地主机上部署了这个 MVC 应用程序(在我运行 Windows 8 的机器上),它按预期运行。我的安装文件夹和服务器上的安装文件夹之间的唯一区别是连接字符串。但是当我尝试在服务器机器(Windows Server 2008)上部署它时,我得到了这个奇怪的错误:

[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个参数)+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

发生这种情况的应用程序中的代码基本上是使用数据库中的一些信息实例化特定类的新对象。你有什么明显的问题吗?可能是连接字符串有问题还是其他原因?

应用视图模型:

 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();

    }
}

和控制器的代码:

 viewModel.Application = new ApplicationViewModel(app);
4

1 回答 1

1

从提供的信息很难判断,但我会很乐意提供帮助。

如果连接字符串不同,我认为数据也可能不同。

当您看到未设置对象时,通常是代码中未实例化的东西。但在这种情况下,它可能是数据。假设一切都在某处实例化,可能没有 ScreenshotURLs?错误消息详细说明了 lambda 错误,因此我假设它与 select 语句有关。

于 2013-08-22T11:01:58.440 回答