-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: catch collectible access non-collectible exception #11259
base: master
Are you sure you want to change the base?
Conversation
Catch the `NotSupportedException` caused by plugins directly using the server's XML serializer and throw a new one with informative messages, notifying the plugin developer that directly using this serializer is not a supported use case. Signed-off-by: gnattu <gnattuoc@me.com>
Emby.Server.Implementations/Serialization/MyXmlSerializer.cs
Dismissed
Show dismissed
Hide dismissed
Co-authored-by: Mark Monteiro <marknr.monteiro@protonmail.com>
Co-authored-by: Mark Monteiro <marknr.monteiro@protonmail.com>
Signed-off-by: gnattu <gnattuoc@me.com>
Instead of this, it might be possible to provide an alternate ServiceProvider when constructing the IPlugin instances in the plugin manager. A custom serviceprovider that wraps the standard one, but throws this exception if an attempt is made to resolve the xml serializer. If that works I think it would be a cleaner solution. |
How would that work? The |
Do we have a minimal repro plugin? |
Not exactly minimal. I tried to create one before, but the minimal version didn't have this problem for some reason. I ended up reproducing the issue with this repository: jumoog/intro-skipper@5d74330 At this specific commit, I can reproduce the issue by clicking "analyze intro" in the scheduled tasks. |
That throws |
I was thinking the plugin would need to construct it's own instance of I am travelling at the moment and don't have regular access to a computer, so feel free to continue on this without additional feedback/approval from me. I was mainly intrigued about looking into this because this same error was what blocked me when I originally tried to implement plugin unloading. Back then, this was a bug in the dotnet runtime (also this and this related bug) that caused this error to pop up any time Perhaps reading through those linked runtime issues might provide some clues on how to get this working. I also came across this documentation article on how to analyze assembly loading issues: https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/collect-details. That all seems pretty complicated/confusing though, so if this quick fix also solves the issue then maybe just go for it 🤷 |
It shows the same exception but caused by different reasons. The bugs you linked are for all XmlSerializer instances created in the plugin, but this instance is created in the server and passed into the constructor. In your bugs, the plugin cannot even be loaded if it wants to initialize an XmlSerializer. For our current situation, passing this instance is fine; it won't block the load of the plugin. Using this serializer from the server side is also fine; the server is using it for plugin config files. However, accessing this instance and using its methods to try to serialize/deserialize in the plugin itself is not supported because it will cause runtime errors like NullReferenceException or even crashes, and that's why you are seeing this Exception. The serializer will generate some dynamic assemblies that is not collectible and hence cannot be used in the plugin.
This should not work by design. The original design of in-process reloading overlooked the problems this approach may cause. This is fine, because even Microsoft overlooked this and have to patch it later in dotnet 7. The way it worked is not supposed to work, and the fact that it actually worked is a bug and should be fixed. We should not try to "get this working" by "analyzing assembly loading issues" because it is not an issue, but a feature limitation. If we really want the plugin to share the serializer with the server, we have to do much more work to replace the XmlSerializer with something that has less runtime magic, such as the DataContractSerializer. However, this obviously requires much more work and will introduce a lot of breaking changes, which is not suitable for 10.9. |
In my opinion, this is also important for the 10.9 release. |
This pull request has merge conflicts. Please resolve the conflicts so the PR can be successfully reviewed and merged. |
Changes
Catch the
NotSupportedException
caused by plugins directly using the server's XML serializer and throw a new one with informative messages, notifying the plugin developer that directly using this serializer is not a supported use case.This is an alternative to #11254 to retain the in-process restart functionality.
This change could have a long-term impact, meaning that our plugins need to use their own XML serializers from now on, and this change may not be limited to 10.9, but also in later versions.
Issues
Fixes #11251