异常详细信息:System.ArgumentNullException:值不能为 null。参数名称:运行时的meth

发布于 2025-01-01 14:29:03 字数 4977 浏览 5 评论 0原文

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

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

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

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

来源错误:

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

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

堆栈跟踪:

[ArgumentNullException:值不能为空。参数名称:meth]
System.Reflection.Emit.DynamicILGenerator.Emit(OpCode 操作码, MethodInfo meth) +9492330 PetaPoco.PocoData.GetFactory(String sql, 字符串 connString、布尔型 ForceDateTimesToUtc、Int32 firstColumn、 Int32 countColumns, IDataReader r) 中 C:\Dev\MyProjectTest\Code\API\Models\PetaPoco.cs:1992
PetaPoco.d__71.MoveNext() 中 C:\Dev\MyProjectTest\Code\API\Models\PetaPoco.cs:765
System.Collections.Generic.List
1..ctor(IEnumerable1 集合) +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,对象[])+96
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,对象[]参数)+51
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary2 个参数)+409
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext 控制器上下文,动作描述符动作描述符,IDictionary
2 参数)+52
System.Web.Mvc.<>c_DisplayClassd.b_a() +127 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter 过滤器,ActionExecutingContext preContext,Func1 延续)+436
System.Web.Mvc.<>c__DisplayClassf.b__c() +61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter 过滤器,ActionExecutingContext preContext,Func
1 延续)+436
System.Web.Mvc.<>c_DisplayClassf.b_c() +61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext、IList1 过滤器、ActionDescriptor actionDescriptor、 IDictionary2 个参数)+305
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext 控制器上下文,字符串操作名称)+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 请求上下文)+39
System.Web.Mvc.<>c_DisplayClass8.b_4() +65
System.Web.Mvc.Async。<>c_DisplayClass1.b_0() +44
System.Web.Mvc.Async.<>c__DisplayClass81.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 步骤,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;
    }

`

I am having a project in which I have my API classes and in that project I have generated the Database.cs. In my MVC project I have refenrenced the API. Uppon running the application I am having the error message as follows, can anyone help please as I can`t understand why I am having this error message.

From http://www.garethelms.org/2011/05/help-getting-started-with-petapoco/#comment-69, I can see that all the GetSetMethod() are GetSetMethod(true) ever since the petaPOCo is installed.

Value cannot be null. Parameter name: meth Description: An unhandled
exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and
where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: meth

Source Error:

Line 1990: } Line 1991: Line
1992: il.Emit(OpCodes.Callvirt,
pc.PropertyInfo.GetSetMethod(true)); // poco Line
1993: Handled = true; Line 1994: }

Source File: C:\Dev\MyProjectTest\Code\API\Models\PetaPoco.cs Line:
1992

Stack Trace:

[ArgumentNullException: Value cannot be null. Parameter name: meth]
System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode,
MethodInfo meth) +9492330 PetaPoco.PocoData.GetFactory(String sql,
String connString, Boolean 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(IEnumerable
1 source) +58
PetaPoco.Database.Fetch(String sql, Object[] args) in
C:\Dev\MyProjectTest\Code\API\Models\PetaPoco.cs:601
PecaTest.NewProject.API.Customer.LoadSortedByName() in
C:\Dev\MyProjectTest\Code\API\Customer.cs:68
PecaTest.NewProject.MvcUI.Models.CustomerListModel..ctor() in
C:\Dev\MyProjectTest\Code\MvcUI\Models\CustomerListModel.cs:14
PecaTest.NewProject.MvcUI.Controllers.CustomerController.GetIndexView()
in
C:\Dev\MyProjectTest\Code\MvcUI\Controllers\CustomerController.cs:82
PecaTest.NewProject.MvcUI.Controllers.CustomerController.Index() in
C:\Dev\MyProjectTest\Code\MvcUI\Controllers\CustomerController.cs:19
lambda_method(Closure , ControllerBase , Object[] ) +96
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase
controller, Object[] parameters) +51
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
controllerContext, IDictionary2 parameters) +409
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary
2
parameters) +52
System.Web.Mvc.<>c_DisplayClassd.b_a()
+127 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, 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 continuation) +436
System.Web.Mvc.<>c_DisplayClassf.b_c()
+61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
controllerContext, IList1 filters, ActionDescriptor actionDescriptor,
IDictionary
2 parameters) +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.WrappedAsyncResult
1.End() +140 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,
Object tag) +54
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,
Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
+52 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+8969117 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

-------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.272


Customer class

` 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;
    }

`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

俯瞰星空 2025-01-08 14:29:04

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

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

更改为

    public bool isObsolete { get; set; }

i have this problem in dapper which in my poco object i defined one field as priave geter after remove private problem solved

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

change to

    public bool isObsolete { get; set; }
毁我热情 2025-01-08 14:29:03

为了使接受的答案更加精确。当我的 POCO 中有一个与数据库表中的列名称匹配的属性但我没有该属性的设置器时,我遇到了这个问题。就我而言,这是我自己计算的属性,因此我并不真正需要表中的数据,并且我希望它是只读的。添加一个空设置器解决了我的问题。

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

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

To make the accepted answer a bit more precise. I ran into this issue when I had a property in my POCO that matched the name of a column in the database table but I didn't have a setter for the property. In my case it was a property that I was computing myself so I didn't really need the data from the table and I intended it to be read-only. Adding an empty setter fixed the problem for me.

A likely better option would be to add the Ignore attribute to that property.

I ultimately ended up removing the column from the table.

怎会甘心 2025-01-08 14:29:03

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

Does your poco have a parameterless constructor ie; no arguments? It will need one. If you've created your own constructor with parameters you won't have a default parameterless constructor which could be causing the reflection code to fail. Maybe that's it.

情独悲 2025-01-08 14:29:03

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

The issue was indeed with the POCO as I missed to set and get the ID

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文