简体   繁体   English

类型'<> f__AnonymousType1`2 [System.String,System.Data.Linq.Binary]'必须声明一个默认(无参数)构造函数

[英]The type '<>f__AnonymousType1`2[System.String,System.Data.Linq.Binary]' must declare a default (parameterless) constructor

I'm getting the exception 我得到了例外

System.InvalidOperationException: The type '<>f__AnonymousType1`2[System.String,System.Data.Linq.Binary]' must declare a default (parameterless) constructor in order to be constructed during mapping. System.InvalidOperationException:类型'<> f__AnonymousType1`2 [System.String,System.Data.Linq.Binary]'必须声明一个默认(无参数)构造函数,以便在映射期间进行构造。

when I try run 当我尝试跑步

await cmd.ExecuteReaderAsync();

a very simple command that returns rows from a table that contains a rowversion ( timestamp, not null ) column. 一个非常简单的命令,该命令从包含rowversion( timestamp, not null )列的表中返回行。 Any idea why? 知道为什么吗? Very strange. 很奇怪。

EDIT: 编辑:

It's actually failing when I run 当我跑步时实际上是失败的

return this.Translate<T>(reader);

directly afterwards. 之后直接。

You are getting this error because you are trying to translate your reader in the type that does not have default constructor. 之所以出现此错误,是因为您试图以没有默认构造函数的类型来翻译您的阅读器。 That means you have defined your own constructor in the type which overrides the default parameterless constructor. 这意味着您已经用覆盖默认无参数构造函数的类型定义了自己的构造函数。

Simple define the parameter less constructor in the Type in which you are trying to translate the reader object and you are done. 只需在尝试转换阅读器对象的Type中定义参数较少的构造函数即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型&#39;&lt;&gt; f__AnonymousType2`2 [System.String,System.Int32]&#39;必须声明一个默认(无参数)构造函数 - The type '<>f__AnonymousType2`2[System.String,System.Int32]' must declare a default (parameterless) constructor 无法将类型为“&lt;&gt; f__AnonymousType1`2 [System.Int64,System.String]”的对象强制转换为“ConsoleApplication1.Profile”。 - Unable to cast object of type '<>f__AnonymousType1`2 [System.Int64,System.String]' to type 'ConsoleApplication1.Profile'. 无法将类型为“ &lt;&gt; f__AnonymousType5`3 [System.String,System.String,System.String]”的对象强制转换为“ System.Data.DataRowView”。 - Unable to cast object of type '<>f__AnonymousType5`3[System.String,System.String,System.String]' to type 'System.Data.DataRowView'.' LINQ,聚合操作不支持“System.Data.Linq.Binary”类型 - The type 'System.Data.Linq.Binary' is not supported in aggregation operations - LINQ 修复反序列化期间没有为“System.String[]”类型定义的无参数构造函数 - Fix for no parameterless constructor defined for type of 'System.String[]' during deserialization 如何将&#39;byte []&#39;类型转换为&#39;System.Data.Linq.Binary&#39; - How to convert type 'byte[]' to 'System.Data.Linq.Binary' 类型“ System.Data.Linq.Binary”在未引用的程序集中定义 - Type 'System.Data.Linq.Binary' is defined in an assembly that is not referenced 无法在LINQ中将类型&#39;string&#39;隐式转换为&#39;System.Data.Linq.Binary - Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary in LINQ to SQL ExecuteMethodCall:类型&#39;System.Nullable`1 [System.DateTime]&#39;必须声明一个默认(无参数)构造函数 - ExecuteMethodCall: The type 'System.Nullable`1[System.DateTime]' must declare a default (parameterless) constructor 在 JSON 反序列化期间没有为“System.String”类型定义无参数构造函数 - No parameterless constructor defined for type of 'System.String' during JSON deserialization
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM