如果我从XML反序列化,我会收到以下错误:The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized.
我的F#代码如下所示:
[<...>]
[<...>]
[<DataContract>]
type DerivedClass() as X = class
inherit BaseClass()
[<DataMember>]
[<Input>]
[<DefaultValue>]
val mutable MemberName: myType
....
我使用ILSpy来查看结果并获取init @ 117值,以便在启动之前防止Access。
...
[..., DataContract]
[System.Serializable]
public class DerivedClass : BaseClass
{
[..., DefaultValue, DataMember]
public modulName.myType MemberName;
internal int init@117;
...
我所有其他类都没有获得init @变量并按预期反序列化。为什么init @有时会创建,有时不会?答案可以帮助我修复我的代码。
修改
@之后的数字代表该类型的源代码行。
修改2
使用as
引用该类型会为HasSelfReferentialConstructor
创建InstanceMembersNeedSafeInitCheck
责备,以便更改
...
type DerivedClass() as X = class
...
到
...
type DerivedClass() = class
...
为我解决了这个问题。
答案 0 :(得分:4)
使用as
引用类型会创建HasSelfReferentialConstructor reponsible for theInstanceMembersNeedSafeInitCheck
,因此更改
...
type DerivedClass() as X = class
...
到
...
type DerivedClass() = class
...
为我解决了这个问题。