Skip to content

Why is TaskCanceledException not being caught but other exceptions are? #70

@dansorescu-mhc

Description

@dansorescu-mhc

I am using Prise Plugin Framework and MailKit SMTP Client.

During the ConnectAsync call, if the async call timeouts, it will throw a TaskCanceledException. This will be caught in the caller and after logging it will be thrown down the call stack. But this will not be caught after the Execute method in the Prise plugin and the app will crash - other exceptions are being caught fine and don't crash the app.

try
{
    await _smtpClient.ConnectAsync(sendEmail.Host, sendEmail.Port);
    // other code
}
catch
{
    // logging
    throw;
}

This code is being called by the plugin with return await service.ExecuteAsync(parameters, context);

I'm expecting this to throw the exception to its parent but it doesn't happen.

The plugin looks as follows:

[Plugin(PluginType = typeof(IPlugin))]
public class Email : BasePlugin<EmailInputModel>
{
	[field: PluginService(ProvidedBy = ProvidedBy.Host, ServiceType = typeof(IServiceProvider))]
	private IServiceProvider ServiceProvider { get; set; }

	[PluginActivated]
	public void OnActivated()
	{
		InitializeServices(ServiceProvider);
	}

	protected override async Task<PluginExecutionResult> ExecutePluginAsync(
		InputModel parameters,
		PluginExecutionContext context,
		IServiceProvider provider)
	{
		IEmailPluginService service = provider.GetRequiredService<IEmailPluginService>();
		return await service.ExecuteAsync(parameters, context);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions