natemcmaster / DotNetCorePlugins

.NET Core library for dynamically loading code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] Shared plugin to plugin data using serialize?

large opened this issue · comments

Thank you for this great plugin library!
I just converted a big project to .Net 5 with an existing plugin system that failed hard on Assembly.Load.
This library saved me hours, but also made some new challenges.

My implimentation share a IDictionary<string, object> objectlist with all kinds of info between the plugins.
One object using the Mimekit ( http://www.mimekit.net/ ) and it failed with the A/B error, because of the isolation between them.
For example; MimeMessage mail = (MimeMessage)objectlist["Mail"];

Basically the same as #159

I tested to serialize the MimeMessage to a byte[] array, and load it again as stream of bytes, that works perfectly.
I wonder if that solution would be robust also in the future of this plugin?
Or do you have other clever solutions up your sleeves?

Please note that a plugin does not know if another plugin has equal Mimekit version installed...

Glad to hear that this project helped you!

This sounds to me like you're doing object serialization and deserialization. If I've understood correctly, this seems like something which is outside the scope of what I'm trying to do with this project. Object (de)serialization is a tricky problem to solve and has potential security implications, so I would be reluctant to add such a feature to this library.

That said, if you think the pattern is useful enough for others and want to release your own library which extends this one, I'd be happy to link to your project or provide extensibility points if needed.

I guess the conversion on a Mailkits MimeMessage is just a special case and can only be used for that specific object.
Worked great so far in my dev-setup.

I do see the security issue of serialization and de-serialization, but I have to trust that Data Execution Protection (DEP) works :)

For those who are interested, this is how I converted data between A/B plugins:

public static class MailkitConvert
{
    /// <summary>
    /// Convert MimeMessage to byte[] array
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static byte[] ToStream(MimeMessage message)
    {
        using (MemoryStream MemStream = new MemoryStream())
        {
            message.WriteTo(MemStream);
            return MemStream.ToArray();
        }
    }

    /// <summary>
    /// Convert byte[] array to MimeMessage
    /// </summary>
    /// <param name="array"></param>
    /// <returns></returns>
    public static MimeMessage ToMimeMessage(byte[] array)
    {
        using (MemoryStream MemStream = new MemoryStream(array))
        {
            return MimeMessage.Load(MemStream);
        }
    }
}