2

I tried to compile the MEF code copied from this page.

using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;
using System;

public class Program
{
[Import]
public IMessageSender MessageSender { get; set; }

public static void Main(string[] args)
{
 Program p = new Program();
 p.Run();
}

public void Run()
{
 Compose();
 MessageSender.Send("Message Sent");
}

private void Compose()
{
 AssemblyCatalog catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
 var container = new CompositionContainer(catalog);
 container.ComposeParts(this);
}
}

public interface IMessageSender
{
void Send(string message);
}

[Export(typeof(IMessageSender))]
public class EmailSender : IMessageSender
{
public void Send(string message)
{
 Console.WriteLine(message);
}
}

When I run this command dmcs example.cs I got this error message.

ex.cs(1,29): error CS0234: The type or namespace name `Composition' does not exist in the namespace `System.ComponentModel'. Are you missing an assembly reference?

What reference library do I need to give to remove this error message?

ADDED

dmcs ex.cs /r:System.ComponentModel.Composition.dll works. One doesn't have to download the dlls from codeplex.

prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

2

Whether or not MEF is included in Mono isn't the issue, I think ... but that you need the MEF library (not included in Mono libraries). Download the library from Codeplex. Then reference it from your project. If that works, then Mono may play nice with it.

IAbstract
  • 19,551
  • 15
  • 98
  • 146
1

Per my understanding, MEF is not part of Mono at this time. Mono has a "similar" construct with AddIn, but it is not identical to MEF. At this time, creating MEF in Mono would mean rolling your own, unless there is some new magic I am missing out on.

Gregory A Beamer
  • 16,870
  • 3
  • 25
  • 32
  • 1
    MEF is a part of mono -> http://www.mono-project.com/Release_Notes_Mono_2.8 and http://stackoverflow.com/questions/3909383/mono-and-mef-are-they-compatible – prosseek Jun 08 '11 at 21:37
  • From my last interaction with Mono, this was the case. Don't look for MEF in Mono - Novell has their own ideas - hmmm, the link @prosseek gave has a link that takes you to the Microsoft MEF page: http://mef.codeplex.com/ on codeplex – IAbstract Jun 08 '11 at 21:38
  • @prosseek: Thanks for the update. Last I had heard, 2.8 was not going to include MEF. Nice to be corrected on something like this. Unfortunately, I have not been on a Mono project recently, so I will accept the correction of my ignorance. – Gregory A Beamer Jun 08 '11 at 21:42