merken / Prise

A .NET Plugin Framework.
https://merken.github.io/Prise
MIT License
361 stars 39 forks source link

System.Text.Json.JsonException when using a plug-in interface with async Task #33

Closed ayfie-frank-gynnild closed 3 years ago

ayfie-frank-gynnild commented 4 years ago

When creating a plug-in contract using an async method that just returns a Task, I get this exception when trying to call the plug-in through Prise:

System.Text.Json.JsonException: 'A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 0.'

It's quite easy is to replicate:

    public interface IMyPlugin
    {
        public Task TestAsync();
    }

    [Plugin(PluginType = typeof(IMyPlugin))]
    public class MyPlugin: IMyPlugin
    {
        public async Task TestAsync()
        {
            await Task.Run(() => Console.WriteLine("Inside of plug-in.")).ConfigureAwait(false);
        }
    }

On the host side, just call:

await plugin.TestAsync().ConfigureAwait(false);

and you get the exception above.

If you change the return to Task<string> or something else, it seems to work fine.

merken commented 4 years ago

Hi,

Returning a void (like an untyped Task) is not supported at the moment, the Prise.Proxy library needs updating in order to fix this. Expect this to be fixed in the next release (.NET 5)

ayfie-frank-gynnild commented 4 years ago

Thanks 👍

merken commented 3 years ago

Hi @snowbirder ,

Please check out Prise 2.0.0, support for the Task return type was added (among other things).

ayfie-frank-gynnild commented 3 years ago

Thanks @merken