System.InvalidOperationException:Each parameter in the deserialization constructor on type ‘‘ must
报错内容:
System.InvalidOperationException:“Each parameter in the deserialization constructor on type 'class Name ***' must bind to an object property or field on deserialization. Each parameter name must match with a property or field on the object. The match can be case-insensitive.”
问题原因:
看这句
Each parameter name must match with a property or field on the object.每个参数名称必须与对象上的属性或字段匹配
因为我的类增加了一个带参数的构造函数,RecaptchaResponse类只有 1 个构造函数,并且该构造函数需要的参数反序列化框架无法解析。
public class RecaptchaResponse
{public RecaptchaResponse(bool success, string errorCodes){Success = success;ErrorCodes = new List<string> { errorCodes };}[JsonPropertyName("success")]public bool Success { get; set; }[JsonPropertyName("score")]public decimal Score { get; set; }[JsonPropertyName("action")]public string Action { get; set; }[JsonPropertyName("challenge_ts")]public DateTime Challenge_ts { get; set; }[JsonPropertyName("hostname")]public string Hostname { get; set; }[JsonPropertyName("error-codes")]public List<string> ErrorCodes { get; set; } = new List<string> { };
}
解决方法:
在反序列化期间,进行反序列化的框架需要能够构造您想要反序列化的对象。
为了能够构造该对象,它需要一个有效的构造函数。似乎它会接受两种类型的构造函数:
1、增加一个空的构造函数
2、增加一个具有与对象的属性名称匹配的参数的构造函数(因此,框架可以通过构造函数填充它们,而不是直接设置属性。
增加一个空的构造函数
public class RecaptchaResponse
{public RecaptchaResponse(){}public RecaptchaResponse(bool success, string errorCodes){Success = success;ErrorCodes = new List<string> { errorCodes };}[JsonPropertyName("success")]public bool Success { get; set; }[JsonPropertyName("score")]public decimal Score { get; set; }[JsonPropertyName("action")]public string Action { get; set; }[JsonPropertyName("challenge_ts")]public DateTime Challenge_ts { get; set; }[JsonPropertyName("hostname")]public string Hostname { get; set; }[JsonPropertyName("error-codes")]public List<string> ErrorCodes { get; set; } = new List<string> { };
}
System.InvalidOperationException:Each parameter in the deserialization constructor on type ‘‘ must相关推荐
- 关于System.InvalidOperationException异常
关于System.InvalidOperationException异常 参考文章: (1)关于System.InvalidOperationException异常 (2)https://www.cn ...
- asp.net 访问 access出现 ole_connection.ServerVersion引发了System.InvalidOperationException的解决
今天在一台电脑上使用asp.net访问access,出现了 ole_connection.ServerVersion引发了System.InvalidOperationException: 下面是解决 ...
- System.InvalidOperationException:“线程间操作无效: 从不是创建控件“txtPortName02”的线程访问它。”...
"System.InvalidOperationException"类型的未经处理的异常在 System.Windows.Forms.dll 中发生 其他信息: 线程间操作无效: ...
- C#——实现IComparableT 接口,ArrayLIst调用ArrayLIst.Sort()抛出System.InvalidOperationException异常解决方案
问题描述 未经处理的异常: System.InvalidOperationException: 未能比较数组中的两个元素. ---> System.ArgumentException: 必须至少 ...
- System.InvalidOperationException: The stream does not support reading
We are using EMS(.Net DLL, TIBCO.EMS.dll, version 4.3.0) as the middleware to communicate between .N ...
- 解决方案:System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。
解决方案:System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分. 参考文章: (1)解决方案:System.Inval ...
- C#无法生成解决方案,System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。
C#无法生成解决方案,System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分. 参考文章: (1)C#无法生成解决方案, ...
- ServerVersion 引发了“System.InvalidOperationException”类型的异常
ServerVersion 引发了"System.InvalidOperationException"类型的异常 参考文章: (1)ServerVersion 引发了"S ...
- EF异常:“System.InvalidOperationException”类型的未经处理的异常在 mscorlib.dll 中发生
EF异常:"System.InvalidOperationException"类型的未经处理的异常在 mscorlib.dll 中发生 参考文章: (1)EF异常:"Sy ...
最新文章
- Xamarin Essentials教程磁力计Magnetometer
- eclipse + android 自动补全
- CSS将样式规则与HTML元素相关联
- Duplicate Strings 字符串 取模 牛客练习赛95
- 快捷键截屏_关于Mac电脑截图,你必须要知道的几个快捷键!(错过会后悔哦)...
- Python中各进制间的转换
- 关于SAP Spartacus Routing 页面上下文切换机制的实现
- 斜堆学习笔记+复杂度证明
- 【C#桌面应用】第二节:利用Visual Studio2019 创建桌面应用
- iOS中copy,retain,strong,assign,weak的区别以及使用
- 获取公司的maven库 和 idea maven 中Projects Settings的Libraries中正常,但是在Maven Projects中Dependencies一直出现红线的解决办法
- 例4.7 素数 - 九度教程第51题(素数筛法)
- python怎样定义font_无法在matplotlib中使用自定义字体
- 数据的提取方法 - 1
- Apache 安装与配置
- 【NEW02】Servlet 基础
- Autoware.auto 毫米波雷达目标检测demo展示
- 帕金森病的功能性脑连接障碍:一项5年的纵向研究
- 宠物店小程序开发线上预约
- HDU-2094(产生冠军)
热门文章
- 你不是真正的快乐---纪念即将完结的青春和陪伴我的阿星和星仔和星爷
- HTML网上书店静态HTML网页作业作品 大学生三联书店网页设计制作成品 简单DIV CSS布局网站...
- Practical Python and OpenCV 3rd Edition读书笔记_Chapter8_Smoothing and Blurring平滑与模糊_思维导图
- 1024 程序员节,拿个勋章
- python selenium 获取网页源代码
- Postman之Mock Servers虚拟服务器
- linux 单网卡绑定两个ip
- 物联网案例研究:确保格兰仕智能设备不易受黑客攻击
- 一个类月光宝盒应用,把手机,电视,盒子变家庭游戏机(FBA,FBNEO,MAME)
- 算法分析之大O、大Ω、大Θ和小o表示法