I’ve made a very simple MEF sample which runs on .NET, but doesn’t work properly on Mono.
using System; using System.Collections.Generic; using System.Text; using System.ComponentModel.Composition; namespace Vialis { class Program { [Import(typeof(ILedController))] public List<ILedController> Controllers { get; set; } static void Main(string[] args) { new Program(); } public Program() { compose(); selectController(); Console.ReadLine(); } private void compose() { var catalog = new DirectoryPartCatalog('controllers'); var container = new CompositionContainer(catalog); container.AddPart(this); container.Compose(); } private void selectController() { Console.Clear(); Console.WriteLine('Please select the controller to use\n'); byte i = 0; foreach (var controller in Controllers) { Console.WriteLine('\t{0}) {1}', i, controller.ToString()); i++; } Console.Write('\nYour selection: '); var input = Convert.ToInt32(Console.ReadLine()); Controllers[input].DisplayText(10, 10, 'Hello World'); } } }
This is the interface:
using System; using System.Collections.Generic; using System.Text; namespace Vialis { public interface ILedController { void DisplayText(int x, int y, string text); } }
This is the first implementation:
using System; using System.Collections.Generic; using System.Text; using System.ComponentModel.Composition; namespace Vialis { [Export(typeof(ILedController))] public class LyanController : ILedController { public void DisplayText(int x, int y, string text) { Console.SetCursorPosition(x, y); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(text); } } }
The second implementation:
using System; using System.Collections.Generic; using System.Text; using System.ComponentModel.Composition; namespace Vialis { [Export(typeof(ILedController))] public class VialisController : ILedController { public void DisplayText(int x, int y, string text) { Console.SetCursorPosition(x, y); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(text); } } }
This is what happens on .NET (Windows):
.NET http://lh5.ggpht.com/_GWubgra2SwM/SXl-yoSRLtI/AAAAAAAADwI/sGR0FjLfg8Q/controller-selection-windows.jpg
Selecting the controllers:
.NET 1 http://lh3.ggpht.com/_GWubgra2SwM/SXl-yYzs-aI/AAAAAAAADwE/WomfaQqv_Xc/vialis-controller-windows.jpg
.NET 2 http://lh6.ggpht.com/_GWubgra2SwM/SXl-yE1Q-cI/AAAAAAAADwA/qznnEkiNokA/lyan-controller-windows.jpg
But using Mono 2.2 the assemblies don’t load:
Mono http://lh5.ggpht.com/_GWubgra2SwM/SXl-xw0YXOI/AAAAAAAADv8/7j2UxJott04/controller-selection-macos.jpg
Any suggestions ?
INFO: Google seems to be having some picasa web problems, that is why the images don’t load.
The pictures show you that on Mac OS, no controllers are listed.
With the latest MEF release (Preview 4 – http://www.codeplex.com/MEF) it works just fine!
Since the bug is no longer relevant I voted to close this question.