If I deserialize from XML I get the following error:The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized.
My F# code looks as following:
[<...>]
[<...>]
[<DataContract>]
type DerivedClass() as X = class
inherit BaseClass()
[<DataMember>]
[<Input>]
[<DefaultValue>]
val mutable MemberName: myType
....
I used ILSpy to look at the result and getting the init@117 value that guards against Access before initilazation.
...
[..., DataContract]
[System.Serializable]
public class DerivedClass : BaseClass
{
[..., DefaultValue, DataMember]
public modulName.myType MemberName;
internal int init@117;
...
All my other classes don't get an init@ variable and deserialize as expected. Why is the init@ sometimes created and sometimes not? The answer could help me to fix my code.
Edit
The number after the @ stands for the sourc code line of the type.
Edit 2
Referencing the type with as
creates the HasSelfReferentialConstructor
reponsible for the InstanceMembersNeedSafeInitCheck
so changing
...
type DerivedClass() as X = class
...
to
...
type DerivedClass() = class
...
solved the issue for me.
Referencing the type with as
creates the HasSelfReferentialConstructorreponsible for theInstanceMembersNeedSafeInitCheck
so changing
...
type DerivedClass() as X = class
...
to
...
type DerivedClass() = class
...
solved the issue for me.