反序列化错误InnerException消息是'ValueType'System.Int32'不能为null [英] Error to deserialize The InnerException message was 'ValueType 'System.Int32' cannot be null

查看:439
本文介绍了反序列化错误InnerException消息是'ValueType'System.Int32'不能为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


 我偶尔会收到这个错误(它发生在大约2个小时之前,但现在我没有得到错误)当调出K2表格时(使用K2)调用WCF服务的SmartObjects。

当我不断收到错误时,它似乎处于不同的函数
 I am getting this error sporadically (it happened all the time about 2 hours ago, but now I am not getting the error) when bring up K2 forms (that uses K2 SmartObjects that calls WCF Service).
When I kept getting the error, it seems to be at different functions

推荐答案

你好aujong,

Hi aujong,

>>" InnerException消息始终相同:'ValueType'System.Int32'不能为空。'"

>>"The InnerException message was always the same: 'ValueType 'System.Int32' cannot be null.'"

是否抛出异常取决于反序列化的消息。例如,如果您的实体是这样的。

Whether the exception will throw depends on the message which was deserialized. For example, If your entity is like this.

public class MyEntity
{
    [Required]
    public int PropertyA { get; set; }
}

如您所见,PropertyA的类型是int,它不能为null。但是,如果邮件未提供PropertyA的信息或为此属性提供null,则会发生异常。例如,

As you see, the type of PropertyA is int and it can't be null. But if the message doesn't provide the information of PropertyA or provide null for this property, the exception will occur. For example,

<MyEnity>
  <PropertyA></PropertyA>
</MyEntity>


<MyEnity>
</MyEntity>

我建议您在deserilizer之前验证xml或json,或者将PropertyA的类型更改为int?(Nullable< int>)可以接受空值。

I suggest you validate the xml or json before deserilizer it or change the type of PropertyA to int?(Nullable<int>) which could accept null value.

最好的问候

李旺

Best Regards
Li Wang


这篇关于反序列化错误InnerException消息是'ValueType'System.Int32'不能为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆