NetDispatcherFaultException: ValueType 'System.Decimal
本文关键字:System Decimal ValueType NetDispatcherFaultException | 更新日期: 2023-09-27 18:06:39
我正在尝试进行WCF调用,但当调用返回到客户端时,我一直得到此错误。我尝试将所有的十进制值设置为非空值,如下所示:
[FaultContract(typeof(AdaptFaultDetail))]
[FaultContract(typeof(BLFaultDetail))]
public IRecord SaveRecord(IRecord theRecord, string transactionId, bool reloadRecordAfterSave)
{
var retVal = GeneralServiceCalls.SaveRecord(theRecord, transactionId, reloadRecordAfterSave);
foreach (var property in retVal.GetType().GetProperties())
{
if (property.PropertyType == typeof(decimal) && property.GetValue(retVal) == null)
{
property.SetValue(retVal, 0);
}
}
return retVal;
}
但是我仍然在客户端得到这个错误:
格式化程序在尝试反序列化消息时抛出异常:在尝试反序列化参数http://tempuri.org/:SaveRecordResult时出现错误。InnerException消息为"ValueType"System。十进制'不能为空'。详情请参见InnerException。
内部例外:
System.Runtime.Serialization。SerializationException: ValueType 'System。十进制'不能为空。at ReadAssetCustomFromXml(XmlReaderDelegator, xmllobjectserializerreadcontext, XmlDictionaryString[], XmlDictionaryString[])
此异常是由消息的序列化程序与反序列化程序没有相同的dll引起的。
在这种情况下,类是过时的,因此,发送方(序列化器)序列化的对象上没有接收方(序列化器)期望的十进制字段,并抛出异常。
我不确定为什么WCF连接甚至被允许发生,但我想这就是WCF的工作方式。