如果我从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值,以防止初始化前的访问。
...
[..., DataContract]
[System.Serializable]
public class DerivedClass : BaseClass
{
[..., DefaultValue, DataMember]
public modulName.myType MemberName;
internal int init@117;
...我的所有其他类都没有得到init@变量并按预期反序列化。为什么init@有时被创建,有时却不存在?答案可以帮助我修正我的代码。
编辑
@后面的数字代表类型的源代码行。
编辑2
使用as引用类型将为更改的InstanceMembersNeedSafeInitCheck创建可回复的HasSelfReferentialConstructor
...
type DerivedClass() as X = class
...至
...
type DerivedClass() = class
...帮我解决了这个问题。
发布于 2017-03-10 11:53:38
使用as引用类型将创建更改的HasSelfReferentialConstructorreponsible for theInstanceMembersNeedSafeInitCheck
...
type DerivedClass() as X = class
...至
...
type DerivedClass() = class
...帮我解决了这个问题。
https://stackoverflow.com/questions/42713001
复制相似问题