Skip to content

Keep original stack trace when rethrowing exceptions #278

@jesperll

Description

@jesperll

When calling Container.Dispose() if a single object throws an exception it gets rethrown in a way that replaces the original stacktrace with one that only includes Container.Dispose()

This makes it impossible to log what fails in a released app. All you get is Container.Dispose threw an exception.

If multiple objects throw exceptions they're wrapped in an AggregateException keeping their original stacktraces intact.

A better way would be to rethrow using ExceptionDispatchInfo.Capture(exceptions[0]).Throw();
This would keep the original stacktrace.

ExceptionDispatchInfo is available in NET45 and NETStandard10 so NET40 would need to keep throwing as it does today.

LifeTimecontainer.Dispose has the exact same issue

ConstructorResolution.ResolveDelegate and DynamicBuildPlanGenerationContext.GetBuildMethod may also have the issue but I'm not entirely sure what the consequence would be here

Metadata

Metadata

Assignees

Labels

Enhancement 🔨Improvement of existing features

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions