我已经在我的localhost(在运行Windows 8的计算机上)上部署了这个MVC应用程序,它按预期运行。我的安装文件夹和服务器上的文件夹之间的唯一区别是连接字符串。但是当我尝试在服务器计算机上部署它时(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, IDictionary
2个参数)+247
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary 2 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
应用程序中发生这种情况的代码基本上是使用数据库中的一些信息实例化特定类的新对象。你看到任何明显的问题吗?它可能是连接字符串的问题,还是其他的东西?
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();
}
}
和控制器的代码:
viewModel.Application = new ApplicationViewModel(app);
答案 0 :(得分:1)
从提供的信息中很难说出来,但我会帮助你。
如果连接字符串不同,我认为数据可能也是如此。
当您看到对象未设置时,通常在代码中未实例化。但在这种情况下,它可能是数据。假设一切都在某处实例化,那么有可能没有ScreenshotURL?错误消息详细说明了lambda错误,因此我假设它与select语句有关。