Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:47:25+00:00 2026-05-27T02:47:25+00:00

I am using MEF to compose a number of components at run time but

  • 0

I am using MEF to compose a number of components at run time but when I use a metadata attribute it double the number of parts in the collection.

When checking the container.ComposeParts I can see that the dll containing the 11 implementation of IStages is loaded once and only the 11 part required appear but when it resolves the Private Property Stages As IEnumerable(Of Lazy(Of IStages, IStagesMetadata)) the number of instances is doubled to 22. Looping through the collections I can see that they are duplicated by the ID in the metadata.

If I don’t use the Metadataattribute on the export or import then I get the expected 11 parts.

Export Attribute

Imports System.ComponentModel.Composition

<MetadataAttribute(), AttributeUsage(AttributeTargets.Class, AllowMultiple:=False)>
Public Class StagesMetadataAttribute
    Inherits ExportAttribute

    Public Property StageID As Byte
    Public Property Version As String

    Public Sub New()
        MyBase.New(GetType(IStages))
    End Sub

End Class

Part Example

Imports System.ComponentModel.Composition
Imports VFRAME.QUALITY.GOODSIN.ESCALATE.INTERFACES

<Export(GetType(IStages))>
<StagesMetadata(StageID:=1, Version:="v1.0.0.0")>
Public Class Stage1
    Implements IStages

    Public Function ProcessEscalation(failure As InspectionFaultsModel) As InspectionFaultsModel Implements IStages.ProcessEscalation
        Return Nothing
    End Function

End Class

Import side constructor

Using catelog As New DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory)
    Using container As New CompositionContainer(catelog)
        Try
            container.ComposeParts(Me)
        Catch ex As CompositionException
            _compositionComplete = False
        End Try
    End Using
End Using

ImportMany

<ImportMany()>
Private Property Stages As IEnumerable(Of Lazy(Of IStages, IStagesMetadata))

Import metadate interface

Public Interface IStagesMetadata
    ReadOnly Property StageID As Byte
    ReadOnly Property Version As String
End Interface

Any idea what the problem is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:47:26+00:00Added an answer on May 27, 2026 at 2:47 am

    Figured it out

    If you decorate the part with the Export and StagesMetadata it creates 2 export definintions for the part as StagesMetadataAttribute inherits from ExportAttribute

    <Export(GetType(IStages))>
    <StagesMetadata(StageID:=1, Version:="v1.0.0.0")>
    Public Class Stage1
        Implements IStages
    
        Public Function ProcessEscalation(failure As InspectionFaultsModel) As InspectionFaultsModel Implements IStages.ProcessEscalation
            Return Nothing
        End Function
    
    End Class
    

    Theres no accounting for stupidity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try for some time to get things done using MEF but now, I
Is there a way using IoC, MEF [Imports], or another DI solution to compose
I am using MEF in a framework to compose worker threads available processors dynamically
Background: I'm using MEF to help compose an Excel 2007 Add-In (VSTO) that can
I'm using MEF for a plugin-system to my application. The flow goes like this:
I am using MEF in Silverlight for dynamic download .xap file. I want to
I've searched high and look for samples about using MEF for DI. I know
I'm doing a proof of concept app in SL4 using MEF and as part
I am missing something basic when it comes to using MEF. I got it
How do we inject IRegionManager in the ViewModel using MEF Container. I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.