Hey, I am having an issue with Introspection and deserialization. Lets say I have some class with primitive properties and properties which are classes.
The deserialization function works on primitives no issues using FieldInfo.SetValue, the deserialization function is recursive so the the below code is the most important snippet for my issue. I broke classOut into a separate variable for testing purposes. The Function is Deserialize(dataIn As String) As Object
Initial Calling of Deserialize from a button.press event
Var loadTest As New TestClass
loadTest = TestClass(SEC.Load("some file path to serialized data")) # I do not see any Auto casting available, the IDE throws an error, cannot assign type Object to type TestClass without forcing the casts, no big deal but I wonder if the Type Cast is the issue and is somehow returning an empty TestClass instance.
Var classOut As Object = Deserialize(dataOut) # Where dataOut is the complete data of the property that is a class.
Var cf As Object = loadObjectType.Field(className) # Where loadObjectType is the parent object Type, className is the field name of the property in the parent object with respect to the child class.
cf.SetValue(loadObject, classOut) # Where loadObject is the parent object, and classOut is the object returned by the Deserialize function
Messagebox("Child | " + classOut.shutdown_code.ToString() + EndOfLine.Native + "Parent | " + loadObject.child.shutdown_code.ToString()) #Results in Child | 25 /n Parent | 25 as expected.
#End of Deserialize function
Return loadObject
Now heading back to our button after deserialize is called
Messagebox(loadtest.child.shutdown_code.ToString()) # NothingReferenceException: Cannot call method 'ToString' because the receiver is Nothing
Messagebox(loadtest.MyInteger.ToString()) #Reports the correct value of MyInteger so the loadtest/loadObject are at least partially intact
I can share more code or even the project file if its easier to figure this out, I am probably doing something wrong but I am so lost lol, loadObject and classOut are both intact but after the return and typecast it dies. I thought this would be an issue with the deserialize function returning an Object but within the scope of the function loadObject is correct it is only once it is returned things go south.