This project has moved and is read-only. For the latest updates, please go here.

Method Exports in

Apr 3, 2009 at 4:31 AM
Ok, I don't know what I am doing wrong here.

Public Class Addin

<Import("Host.NextEvent")> _
Public NextEvent As Action(Of String, String, String)

Public Sub RaiseNextEvent()
    If Not NextEvent Is Nothing Then
        NextEvent(Me.tSource.Text, tDestination.Text, tRobocopy.Text)
    End If
End Sub

End Class

Public Class Host

<Export("Host.NextEvent")> _
Public Sub SelectionEnabled(ByVal source As String, ByVal destination As String, ByVal robocopy As String)
	bNext.IsEnabled = True
	MsgBox("Selection Enabled Event!")

End Sub

End Class

The problem I am having, is in the RaiseNextEvent() method. The NextEvent object is always nothing.

Also, the [Export(type, contractName)] does not work for me in vb. I get the error: Overload resolution failed because no accessible 'New' accepts this number of arguments.



Apr 3, 2009 at 5:34 AM
Hi Rick

Your Addin class needs to have an Export attribute. MEF recognizes the presence of an Export attribute as an indication that it is a part.

On the [Export(type,contractName)] not working, can you post the VB code that you are trying to write?

Apr 3, 2009 at 6:08 AM
Edited Apr 3, 2009 at 6:15 AM
Both the import and export classes are exported on their type, e.g. <Export(GetType(Host))> _ or <Export(GetType(Addin))> _.

Constructor on Export attribute
If I do this:

<Export(GetType(Addin1), "Some Contract")> _
Public Class Addin1
End Class

No matter what class, the two parameter constructor (type, [ContractName]) gets this error. This is the build 28358 posted in the source folder.

I can only do type or contract name, not both. The (type, [ContractName]) shows up in intellisense, but when I use it, it is underlined with the error.

Apr 3, 2009 at 6:18 AM
Hi Rick

What are you trying to do exactly? 

In the current bits of MEF you can supply both a type and a contact. When you pass a type, it is converted to a contract behind the scenes with a name similar to the Type.Fullname, and the type is discarded. It is really only a syntactic sugar. At runtime type only comes into play when "Some Contract" is imported. As long as Addin1 is castable to the type of the importer it will succeed.

Now in our next drop, we are actually taking type a bit further with a new feature called Type Identity. With Type Identity we will actually carry the type information, which will be used as part of the matching in additon to the contract name.


Apr 3, 2009 at 7:22 AM
Sounds good, type identity is a good idea.

What I am trying to do, is my main window is loading a xaml page. On the page, I load an addin's property (System.Windows.Controls.UserControl)

I am trying to export a method in the xaml page to have the user control call that method directly to enable a button.

It doesn't seem to wire up correctly, or am I just doing it the wrong way?
Apr 3, 2009 at 7:29 AM

Can you email me the code?