【问题标题】:The value passed in must be an enum base or an underlying type for an enum, such as an Int32.Parameter name: value传入的值必须是枚举基类或枚举的基础类型,例如 Int32。参数名称:值
【发布时间】:2014-09-08 06:45:04
【问题描述】:

在 IIS7 上部署我的网站后,我不断在多个页面上收到此错误。当我在visual studio(即localhost)上运行时它不会出现。

附加的是堆栈跟踪:

错误代码

    public ViewResult Index()
    {
       ObjectParameter output = new ObjectParameter("OUT_RESULT", DbType.String);
       ObjectParameter outputdesc = new ObjectParameter("OUT_RESULTDESC", DbType.String);

       var deliveredShipments = db.PODDownload_SearchAllSP(Guid.Parse(Membership.GetUser().ProviderUserKey.ToString()), output, outputdesc);
       ViewBag.IsFirstLoad = true;
       ViewBag.ErrorMessage = "";
       return View(deliveredShipments.ToList());
    } 

【问题讨论】:

  • 您应该显示重现您的问题的错误代码或示例代码。
  • @Sayse 问题不会在开发环境中重现。我附上了给出错误的代码。
  • 您附上了代码,但它没有解释错误发生在哪一行?如果您放大到 150%,堆栈跟踪上的非常小的文本似乎暗示了 toList 调用。那么下一个问题是你是否调试了PODDownload_SearchAllSP 所做/返回的内容?
  • @Sayse 返回 View(deliveredShipments.ToList()) 的行导致了问题。但问题是在调试时我没有收到任何错误,它在我的本地主机上运行良好,当我将它发布到服务器出现。不仅在这里,还有其他几个页面。

标签: c# asp.net-mvc iis-7 enums


【解决方案1】:

这个语句导致了异常:

    ObjectParameter output = new ObjectParameter("OUT_RESULT", DbType.String);
    ObjectParameter outputdesc = new ObjectParameter("OUT_RESULTDESC", DbType.String);

我把它改成了以下:

    ObjectParameter output = new ObjectParameter("OUT_RESULT", "");
    ObjectParameter outputdesc = new ObjectParameter("OUT_RESULTDESC", "");

这解决了这个问题,虽然我无法弄清楚为什么这会在部署后导致问题,而不是在 VS2010 上。我想这与实体框架版本有关。

【讨论】:

  • 我通过显式中断 ArgumentException 在我的代码中找到了此错误的根源(在 Visual Studio 的“异常设置”窗格中检查它)。这是因为 Enum.GetName 被传递了 stringvalue 而不是数字或枚举值。
猜你喜欢
  • 2017-08-01
  • 1970-01-01
  • 2012-03-09
  • 1970-01-01
  • 2019-08-29
  • 2016-11-30
  • 1970-01-01
  • 2019-04-10
  • 1970-01-01
相关资源
最近更新 更多