- Notifications
You must be signed in to change notification settings - Fork768
Best effort serialization#1892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Best effort serialization#1892
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This commit adds a "last line of defense, best effort serialization"to serialize types not marked as Serializable. Such objects aredeserialized as derived classes with all methods and propertiesoverriden to throw a "Not Serialized" Exception.Fields are not initialized and may be null.Sealed classes and implemented interface methods are still a problem tobe solved.
plus guard rails for private classesand review fixes
don't try to derive from sealed types
BadSingleton commentedJul 29, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Also just a note that I'll soon be away for vacations until october, I just want to get that ball rolling and gather feedback in the meantime. |
lostmsu commentedJul 29, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@BadSingleton is there a way to provide that functionality without bringing the |
lostmsu commentedJul 29, 2022
Also, can you describe the approach in more details? |
BadSingleton commentedJul 29, 2022
@lostmsu I think the serializer was meant to be overridable in the first implementations of the serialization. I think I recall@amos402 saying something about the need for users to implement their own. If it becomes overridable we probably can keep it outside of this repo (just need to make sure with some order of initialization things) The idea was to ensure that the presence of a non-serializable object in the graph wouldn't throw an exception, therefore corrupting the whole shutdown process and causing crashes on domain (un)load. As sometimes those objects are outside of our control, we can't modify them and/or avoid easily to serialize them (and/or the users of our APIs may be passing a Unity object that is not serializable). After a few google searches I found out that serialization surrogates could be used to serialize objects not marked
When serializing a derived |
BadSingleton commentedJul 29, 2022
Ignore the part of the previous comment about the serializer not being overridable, I misremembered the code, itis overridable. |
lostmsu commentedJul 29, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It seems that this code can be abstracted out of this repo with:
|
BadSingleton commentedJul 29, 2022
Worst case, |
larryPlayabl commentedDec 20, 2023
I am also experiencing this issue when trying to use this library with Unity3D. Here is the specific serialization error I get on shutdown.@BadSingleton, does your fix prevent this and allow you to initialize and shutdown the python engine multiple times without error? |
BadSingleton commentedJan 4, 2024
Hello,@larryPlayabl. It has been a while, but if my memory serves right, this looks like the exact error this fix was made for. For added convenience, Unity's Python Scripting package has already that fix since version 6.0.0 |
BadSingleton commentedMar 7, 2024
Closing, superseded by#2336 |
Uh oh!
There was an error while loading.Please reload this page.
What does this implement/fix? Explain your changes.
This PR adds a "last line of defense, best effort serialization" to serialize types not marked as Serializable. Such objects, when derivable, are deserialized as derived classes with all (overridable) methods and properties overriden to throw a "Not Serialized" Exception. Fields are not initialized and may be null. Instances of classes that are not derivable are null.
Does this close any currently open issues?
No, but it is an issue we've encountered with Unity.
Any other comments?
This is a "best effort" to ensure no SerializationExceptions are thrown on domain unloads/reloads. This should help users deal with serialization issues as sometimes unserializable classes may be in compiled libraries and therefore unmodifiable.
Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG