Skip to content

System.Composition: CompositionContext.TryGetExport throws CompositionFailedException #31010

Open
@davidmilligan

Description

@davidmilligan

The CompositionContext.TryGetExport method can throw a CompositionFailedException. This violates the common convention/expectation that TryXXX methods don't throw, instead they just return false.

I would expect that calling GetExport would throw an exception in this situation but I would expect that TryGetExport would simply return false.

Stack Trace:

An exception of type 'System.Composition.Hosting.CompositionFailedException' occurred in System.Composition.Hosting.dll but was not handled in user code: 'The component (unknown) cannot be created outside the Scoped sharing boundary.'
   at System.Composition.Hosting.Core.LifetimeContext.FindContextWithin(String sharingBoundary)
   at System.Composition.TypedParts.ActivationFeatures.LifetimeFeature.<>c__DisplayClass1_0.<RewriteActivator>b__0(LifetimeContext c, CompositionOperation o)
   at System.Composition.Hosting.Core.CompositionOperation.Run(LifetimeContext outermostLifetimeContext, CompositeActivator compositionRootActivator)
   at System.Composition.Hosting.Core.LifetimeContext.TryGetExport(CompositionContract contract, Object& export)
   at System.Composition.CompositionContext.TryGetExport(Type exportType, String contractName, Object& export)
   at System.Composition.CompositionContext.TryGetExport(Type exportType, Object& export)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions