This project has moved. For the latest updates, please go here.

Stuck with a discovery problem

Dec 2, 2009 at 2:59 PM

OK, I think I must be short of coffee this morning. I have this export

<Export(GetType(MainPage))> _
Partial Public Class MainPage
   Inherits UserControl

Where the explicit type was added because of this failure, it happens whether or not that line is there

And this import and usage:

Partial Public Class App
   Inherits Application

   Public Sub New()
   End Sub

   <Import(AllowDefault:=True)> _
   Public _mainPage As TestApplication.MainPage

   <ImportMany()> _
   Public _businessServiceClassFactory As IEnumerable(Of Lazy(Of Contracts.IBusinessServiceClassFactory))

   Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
      If _mainPage Is Nothing Then
         Me.RootVisual = New TestApplication.MainPage
         'Throw New InvalidOperationException("Main page not discovered")
         Me.RootVisual = _mainPage
      End If
   End Sub

And, the Main page is found and loaded when used explicitly so there are no xaml errors confusing things.

The MainPage import is not fulfilled.

MainPage has not MEF imports so it seems that it can't be a stable composition problem although it feels like one. Also, there is no composition metadata to confuse things. It's just a dirt simple sample.

So, does anyone see what I'm missing?




Dec 2, 2009 at 3:02 PM

BTW, this is Silverlight 3 and the November MEF drop.


Dec 2, 2009 at 3:18 PM

I'm missing something obvious here. When I step into the MEF code,

            // Ignoring return value because we don't need to know if we created it or not
            CompositionHost.TryGetOrCreateContainer(_createContainer, out container);


And put a break point on the final closing curly I get this result in the Immediate Window:

? container.Catalog.Parts.ToArray()
? ((AggregateCatalog)container.Catalog).Catalogs.ToArray()

So, I thought SatisfyImports grabbed all the exports in the current XAP file in Silverlight. Obviously that's not happening, either because there is something else I've forgotten to do or some other issue. I'm assuming this is a problem between the keyboard and chair on a bad day.




Dec 2, 2009 at 8:42 PM

Ok, this problem cleared up when I reverted to an earlier version of MEF. I'll try redownloading the November bits when I get the chance


Dec 2, 2009 at 10:09 PM

When we first released Preview 8, it was broken and PI did not work propertly as the code to populate based on the XAP was commented out :-)

We updated that code recently so I wonder if you had the version before the update. You might try downloading again.



Dec 2, 2009 at 10:10 PM

Actually you discovered that problem when the grid wasn't working. Is it possible you add older bits for that project?