【问题标题】:Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: meth when running异常详细信息:System.ArgumentNullException:值不能为空。参数名称:运行时的meth
【发布时间】:2012-02-24 20:09:43
【问题描述】:

我有一个项目,其中有我的 API 类,并且在该项目中我生成了 Database.cs。在我的 MVC 项目中,我引用了 API。运行应用程序时,我收到如下错误消息,任何人都可以帮忙,因为我不明白为什么我会收到此错误消息。

http://www.garethelms.org/2011/05/help-getting-started-with-petapoco/#comment-69,我可以看到自从安装了petaPOCo以来,所有的GetSetMethod()都是GetSetMethod(true)。

值不能为空。参数名称:meth 描述:一个未处理的 执行当前 Web 请求期间发生异常。 请查看堆栈跟踪以获取有关错误的更多信息和 它起源于代码的地方。

异常详细信息:System.ArgumentNullException:值不能为空。 参数名称:meth

来源错误:

第 1990 行:} 第 1991 行:行 1992: il.Emit(OpCodes.Callvirt, pc.PropertyInfo.GetSetMethod(true)); // poco 线 1993:已处理 = 真;第 1994 行:}

源文件:C:\Dev\MyProjectTest\Code\API\Models\PetaPoco.cs 行: 1992

堆栈跟踪:

[ArgumentNullException:值不能为空。参数名称:甲基]
System.Reflection.Emit.DynamicILGenerator.Emit(操作码操作码, MethodInfo meth) +9492330 PetaPoco.PocoData.GetFactory(String sql, 字符串 connString,布尔型 ForceDateTimesToUtc,Int32 firstColumn, Int32 countColumns, IDataReader r) in C:\Dev\MyProjectTest\Code\API\Models\PetaPoco.cs:1992
PetaPoco.d__71.MoveNext() in C:\Dev\MyProjectTest\Code\API\Models\PetaPoco.cs:765
System.Collections.Generic.List
1..ctor(IEnumerable1 collection) +327 System.Linq.Enumerable.ToList(IEnumerable1 来源) +58
PetaPoco.Database.Fetch(String sql, Object[] args) 在 C:\Dev\MyProjectTest\Code\API\Models\PetaPoco.cs:601
PecaTest.NewProject.API.Customer.LoadSortedByName() 在 C:\Dev\MyProjectTest\Code\API\Customer.cs:68
PecaTest.NewProject.MvcUI.Models.CustomerListModel..ctor() 在 C:\Dev\MyProjectTest\Code\MvcUI\Models\CustomerListModel.cs:14
PecaTest.NewProject.MvcUI.Controllers.CustomerController.GetIndexView() 在 C:\Dev\MyProjectTest\Code\MvcUI\Controllers\CustomerController.cs:82
PecaTest.NewProject.MvcUI.Controllers.CustomerController.Index() 在 C:\Dev\MyProjectTest\Code\MvcUI\Controllers\CustomerController.cs:19
lambda_method(闭包, ControllerBase, Object[]) +96
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,Object[] 参数)+51
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext 控制器上下文,IDictionary2 parameters) +409
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 参数)+52
System.Web.Mvc.c_DisplayClassd.b_a() +127 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter 过滤器,ActionExecutingContext preContext,Func1 continuation) +436
System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 继续)+436
System.Web.Mvc.c_DisplayClassf.b_c() +61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext,IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 个参数)+305
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
System.Web.Mvc.Controller.ExecuteCore() +136
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.c_DisplayClass8.b_4() +65
System.Web.Mvc.Async.c_DisplayClass1.b_0() +44
System.Web.Mvc.Async.c__DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _) +42 System.Web.Mvc.Async.WrappedAsyncResult1.End() +140 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+54
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult 结果)+38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8969117 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

----------------------------------- --------------------------------- 版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.272


客户类别

` private int id = 0;
    public  int ID
    {
        get { return id; }
        set { id = ID; }
    }

    protected string name;
    public Customer() { }

    public Customer(string name)
    {
        this.name = name;
    }

    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    public override string ToString()
    {
        return name;
    }

`

【问题讨论】:

  • 您能否提供更多信息。波科用过吗?用法?干杯

标签: petapoco


【解决方案1】:

使接受的答案更准确。当我的 POCO 中有一个属性与数据库表中的列名匹配但我没有该属性的设置器时,我遇到了这个问题。就我而言,这是我自己计算的属性,所以我并不真正需要表中的数据,我打算将其设为只读。添加一个空的二传手为我解决了这个问题。

可能更好的选择是将 Ignore 属性添加到该属性。

我最终从表格中删除了该列。

【讨论】:

  • 私有设置的属性也会发生同样的情况,例如:{get; private set;}
【解决方案2】:

您的 poco 是否有无参数构造函数,即;没有论据?它需要一个。如果您使用参数创建了自己的构造函数,则不会有默认的无参数构造函数,这可能会导致反射代码失败。也许就是这样。

【讨论】:

  • 如果失败,您是否运行调试器并检查 pc 的值。绝对是您期望的 poco 吗?我同意 Schotime 的观点,我们没有足够的信息继续下去
【解决方案3】:

问题确实出在 POCO 上,因为我错过了设置和获取 ID

【讨论】:

    【解决方案4】:

    我在 dapper 中遇到了这个问题,在我的 poco 对象中,我在解决了删除私有问题后将一个字段定义为私有 geter

        public bool isObsolete { **private** get; set; }
    

    改成

        public bool isObsolete { get; set; }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-17
      • 2018-06-03
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-01
      • 2021-10-23
      相关资源
      最近更新 更多