Closed waleywu closed 1 year ago
If the type file is stored separately in a cs file, OnDeserialized is invalid
The DirectoryAccount type is stored in a separate file
What? I do not understand. What exactly do you mean?
Your problem is definitely not due to the source code being organized simply in different cs files. There must be more to it that you did not include in your problem description. Can you explain by giving a concrete and complete example that reproduces the problem you are having?
I rather suspect you included the wrong namespace(s) when writing your source code. Because both Newtonsoft.Json
as well as System.Text.Json.Serialization
namespaces provide a JsonExtensionDataAttribute type.
And i strongly suspect you included the System.Text.Json.Serialization
namespace in your source code, therefore the wrong JsonExtensionDataAttribute is being used. Newtonsoft.Json only looks for its own JsonExtensionDataAttribute type contained in the Newtonsoft.Json
namespace. Therefore, make sure you do not import/use the System.Text.Json.Serialization
namespace in your DirectoryAccount.cs source code.
Thank you for reminding me. What you said is correct
I rather suspect you included the wrong namespace(s) when writing your source code. Because both
Newtonsoft.Json
as well asSystem.Text.Json.Serialization
namespaces provide a JsonExtensionDataAttribute type.And i strongly suspect you included the
System.Text.Json.Serialization
namespace in your source code, therefore the wrong JsonExtensionDataAttribute is being used. Newtonsoft.Json only looks for its own JsonExtensionDataAttribute type contained in theNewtonsoft.Json
namespace. Therefore, make sure you do not import/use theSystem.Text.Json.Serialization
namespace in your DirectoryAccount.cs source code.
Source/destination types
Source/destination JSON
Expected behavior
Actual behavior
Steps to reproduce
The DirectoryAccount type is stored in a separate file, then _additionalData.Count ==0. _additionalData.Count ==1 if it is and in the test.cs file,