Skip to content
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

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

Closed
ayfie-frank-gynnild opened this issue Jul 29, 2020 · 4 comments

Comments

@ayfie-frank-gynnild
Copy link

ayfie-frank-gynnild commented Jul 29, 2020

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
Copy link
Owner

merken commented Jul 30, 2020

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
Copy link
Author

Thanks 👍

@merken
Copy link
Owner

merken commented Oct 29, 2020

Hi @snowbirder ,

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

@merken merken closed this as completed Oct 29, 2020
@ayfie-frank-gynnild
Copy link
Author

Thanks @merken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants