Quantcast
Channel: Managed Extensibility Framework
Viewing all 265 articles
Browse latest View live

Created Issue: DirectoryCatalog and assembly with same name, bug? [14605]

$
0
0
Hi All,

I have a scenario where my application (say Program.exe) runs from a Bin folder. There is a Bin/Plugins folder which has some more assemblies (say Plugin1.dll and Plugin2.dll). For some reasons I also have a Plugin1.dll in the Bin folder. (So Plugin1.dll exists in Bin and in Plugins folder). Both DLLs have a little different implementation (another story!)

Next I am creating a DirectoryCatalog for Plugins Folder, and in the output log I see that as soon as I create a DirectoryCatalog for Plugins folder, MEF seems to load the Plugin1.dll from Bin folder, where as I expected it to load the Plugin1.dll from Bin/Plugins folder, as that is where the DirectoryCatalog points to.

I think that even though internal code in DirectoryCatalog intends to load Bin/Plugin/Plugin1.dll, but when it actually loads the dll, it just loads it from the current folder where Program.exe is being run from.

As a different test, I removed the Bin/Plugins/Plugin1.dll and kept the Plugin1.dll in Bin, then it does NOT even look for Plugin1.dll, so it confirms that while creating the DirectoryCatalog object, it certainly looks at Bin/Plugin folder (which is correct) but when it comes to load, it loads Plugin1.dll from the current folder, instead of the folder passed to DirectoryCatalog.

Can anyone confirm that this is not the correct behavior, or if it is, then why?

Thanks!
Ravneet

New Post: DirectoryCatalog issue. Loads the assembly from Current folder instead.

$
0
0
Hi All,

I have a scenario where my application (say Program.exe) runs from a Bin folder. There is a Bin/Plugins folder which has some more assemblies (say Plugin1.dll and Plugin2.dll). For some reasons I also have a Plugin1.dll in the Bin folder. (So Plugin1.dll exists in Bin and in Plugins folder). Both DLLs have a little different implementation (another story!)

Next I am creating a DirectoryCatalog for Plugins Folder, and in the output log I see that as soon as I create a DirectoryCatalog for Plugins folder, MEF seems to load the Plugin1.dll from Bin folder, where as I expected it to load the Plugin1.dll from Bin/Plugins folder, as that is where the DirectoryCatalog points to.

I think that even though internal code in DirectoryCatalog intends to load Bin/Plugin/Plugin1.dll, but when it actually loads the dll, it just loads it from the current folder where Program.exe is being run from.

As a different test, I removed the Bin/Plugins/Plugin1.dll and kept the Plugin1.dll in Bin, then it does NOT even look for Plugin1.dll, so it confirms that while creating the DirectoryCatalog object, it certainly looks at Bin/Plugin folder (which is correct) but when it comes to load, it loads Plugin1.dll from the current folder, instead of the folder passed to DirectoryCatalog.

Can anyone confirm that this is not the correct behavior, or if it is, then why?

Thanks!
Ravneet

New Post: MEF instantiating event subscribers

$
0
0
Hello TobiasFunke!
I tried to use your trick to initiate Subscribers to events in prism, but did not work.

Could u please provide me complete code for your implementation?

Thanks.

New Post: MEF instantiating event subscribers

$
0
0
Hi,

Ensure your IStartable implementations are decorated with the appropriate export attribute, which in this case would be:
[Export(typeof(IStartable)]
public class Car : IStartable
{
    ...
}
This way the container will be able to import them (the IStartable's) when the container initializes.

You could also define an abstract Startable class that implements the IStartable and have all Startable (IStartable implementations) classes derive from that abstract base class which would allow your Startables to inherit the Start() method from the base class and not have to explicitly define that method for each implementation of IStartable.


It's me Tobias btw, lost my old password for that account.

New Post: MEF instantiating event subscribers

$
0
0
Hello!
Thanks for your help! But I still have some issues . Have a look at the following code:-

Interface:
[InheritedExport]
    public interface IMessageConsumer
    {
        void Start();
    }
Subscriber:
[Export(typeof(IMessageConsumer))]
    public class MessageConsumer : IMessageConsumer
    {

        [Import]
        IEventAggregator eventAggregator { get; set; }

        public void Start()
        {
            eventAggregator.
                GetEvent<CompositePresentationEvent<SharedMessage>>().
                Subscribe(OnDataReceived, true);
            //keep waiting for message 
            Thread.Sleep(-1);
        }

        // should be public!
        public void OnDataReceived(SharedMessage txt)
        {
            MessageBox.Show(txt.Message);
        }
Publisher:
[Export(typeof(PublisherView))]
    public partial class PublisherView : UserControl
    {
        [Import]
        public IEventAggregator TheEventAggregator;

        public PublisherView()
        {
            InitializeComponent();
            button1.Click += new RoutedEventHandler(button1_Click);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            // get a reference to the event from 
            // the event aggregator
            CompositePresentationEvent<SharedMessage> myMessageEvent =
                TheEventAggregator.GetEvent<CompositePresentationEvent<SharedMessage>>();

            //Set a message to be published
            SharedMessage message = new SharedMessage
            {
                Message = "Vivane"
            };

            //publish data via event aggregator
            myMessageEvent.Publish(message);
        }
    }
Helper class:
public class SharedMessage
    {
        public string Message { get; set; }
    }
Bootstrapper:
public void Start()
        {            
            //var consumers = this._CompositionContainer.GetExportedValues<IMessageConsumer>();
            var consumers = this.Container.GetExportedValues<IMessageConsumer>();

            // Start event subscribers who are now listening. These types are not injected so as to reduce coupling.
            foreach (var consumer in consumers)
            {
                var task = new Task(consumer.Start);
                task.Start();
            }
        }

protected override void ConfigureContainer()
        {            
            base.ConfigureContainer();
            //this._CompositionContainer = new CompositionContainer(this.AggregateCatalog);
            Start();
           
        }
Issues:
  1. The MessageConsumer shows received message two times. What is the main reason?
  2. In your example U called GetExportedValues method on static CompositionContainer class. I got this error:
    "An object reference is required for the non-static field, method, or property 'System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValues<T>"
I then decided to use this.Container.GetExportedValues<> as it has been shown above. Is it ok?

I'm so sorry for asking very basic questions. Im very new to Software dev and Prism|MEF as well.

Thanks.

user233223 wrote:
Hi,

Ensure your IStartable implementations are decorated with the appropriate export attribute, which in this case would be:
[Export(typeof(IStartable)]
public class Car : IStartable
{
    ...
}
This way the container will be able to import them (the IStartable's) when the container initializes.

You could also define an abstract Startable class that implements the IStartable and have all Startable (IStartable implementations) classes derive from that abstract base class which would allow your Startables to inherit the Start() method from the base class and not have to explicitly define that method for each implementation of IStartable.


It's me Tobias btw, lost my old password for that account.

New Post: MEF instantiating event subscribers

$
0
0
Hello!
Thanks for your help! But I still have some issues . Have a look at the following code:-

Interface:
[InheritedExport]
    public interface IMessageConsumer
    {
        void Start();
    }
Subscriber:
[Export(typeof(IMessageConsumer))]
    public class MessageConsumer : IMessageConsumer
    {

        [Import]
        IEventAggregator eventAggregator { get; set; }

        public void Start()
        {
            eventAggregator.
                GetEvent<CompositePresentationEvent<SharedMessage>>().
                Subscribe(OnDataReceived, true);
            //keep waiting for message 
            Thread.Sleep(-1);
        }

        // should be public!
        public void OnDataReceived(SharedMessage txt)
        {
            MessageBox.Show(txt.Message);
        }
Publisher:
[Export(typeof(PublisherView))]
    public partial class PublisherView : UserControl
    {
        [Import]
        public IEventAggregator TheEventAggregator;

        public PublisherView()
        {
            InitializeComponent();
            button1.Click += new RoutedEventHandler(button1_Click);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            // get a reference to the event from 
            // the event aggregator
            CompositePresentationEvent<SharedMessage> myMessageEvent =
                TheEventAggregator.GetEvent<CompositePresentationEvent<SharedMessage>>();

            //Set a message to be published
            SharedMessage message = new SharedMessage
            {
                Message = "Vivane"
            };

            //publish data via event aggregator
            myMessageEvent.Publish(message);
        }
    }
Helper class:
public class SharedMessage
    {
        public string Message { get; set; }
    }
Bootstrapper:
public void Start()
        {            
            //var consumers = this._CompositionContainer.GetExportedValues<IMessageConsumer>();
            var consumers = this.Container.GetExportedValues<IMessageConsumer>();

            // Start event subscribers who are now listening. These types are not injected so as to reduce coupling.
            foreach (var consumer in consumers)
            {
                var task = new Task(consumer.Start);
                task.Start();
            }
        }

protected override void ConfigureContainer()
        {            
            base.ConfigureContainer();
            //this._CompositionContainer = new CompositionContainer(this.AggregateCatalog);
            Start();
           
        }
Issues:
  1. The MessageConsumer shows received message two times. What is the main reason?
  2. In your example U called GetExportedValues method on static CompositionContainer class. I got this error:
    "An object reference is required for the non-static field, method, or property 'System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValues<T>"
I then decided to use this.Container.GetExportedValues<> as it has been shown above. Is it ok?

I'm so sorry for asking very basic questions. Im very new to Software dev and Prism|MEF as well.

Thanks.

user233223 wrote:
Hi,

Ensure your IStartable implementations are decorated with the appropriate export attribute, which in this case would be:
[Export(typeof(IStartable)]
public class Car : IStartable
{
    ...
}
This way the container will be able to import them (the IStartable's) when the container initializes.

You could also define an abstract Startable class that implements the IStartable and have all Startable (IStartable implementations) classes derive from that abstract base class which would allow your Startables to inherit the Start() method from the base class and not have to explicitly define that method for each implementation of IStartable.


It's me Tobias btw, lost my old password for that account.

New Post: MEF instantiating event subscribers

$
0
0
Hello!
Thanks for your help! But I still have some issues . Have a look at the following code:-

Interface:
[InheritedExport]
    public interface IMessageConsumer
    {
        void Start();
    }
Subscriber:
[Export(typeof(IMessageConsumer))]
    public class MessageConsumer : IMessageConsumer
    {

        [Import]
        IEventAggregator eventAggregator { get; set; }

        public void Start()
        {
            eventAggregator.
                GetEvent<CompositePresentationEvent<SharedMessage>>().
                Subscribe(OnDataReceived, true);
            //keep waiting for message 
            Thread.Sleep(-1);
        }

        // should be public!
        public void OnDataReceived(SharedMessage txt)
        {
            MessageBox.Show(txt.Message);
        }
Publisher:
[Export(typeof(PublisherView))]
    public partial class PublisherView : UserControl
    {
        [Import]
        public IEventAggregator TheEventAggregator;

        public PublisherView()
        {
            InitializeComponent();
            button1.Click += new RoutedEventHandler(button1_Click);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            // get a reference to the event from 
            // the event aggregator
            CompositePresentationEvent<SharedMessage> myMessageEvent =
                TheEventAggregator.GetEvent<CompositePresentationEvent<SharedMessage>>();

            //Set a message to be published
            SharedMessage message = new SharedMessage
            {
                Message = "Vivane"
            };

            //publish data via event aggregator
            myMessageEvent.Publish(message);
        }
    }
Helper class:
public class SharedMessage
    {
        public string Message { get; set; }
    }
Bootstrapper:
public void Start()
        {            
            //var consumers = this._CompositionContainer.GetExportedValues<IMessageConsumer>();
            var consumers = this.Container.GetExportedValues<IMessageConsumer>();

            // Start event subscribers who are now listening. These types are not injected so as to reduce coupling.
            foreach (var consumer in consumers)
            {
                var task = new Task(consumer.Start);
                task.Start();
            }
        }

protected override void ConfigureContainer()
        {            
            base.ConfigureContainer();
            //this._CompositionContainer = new CompositionContainer(this.AggregateCatalog);
            Start();
           
        }
Issues:
  1. The MessageConsumer shows received message two times. What is the main reason?
  2. In your example U called GetExportedValues method on static CompositionContainer class. I got this error:
    "An object reference is required for the non-static field, method, or property 'System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValues<T>"
I then decided to use this.Container.GetExportedValues<> as it has been shown above. Is it ok?

I'm so sorry for asking very basic questions. Im very new to Software dev and Prism|MEF as well.

Thanks.

user233223 wrote:
Hi,

Ensure your IStartable implementations are decorated with the appropriate export attribute, which in this case would be:
[Export(typeof(IStartable)]
public class Car : IStartable
{
    ...
}
This way the container will be able to import them (the IStartable's) when the container initializes.

You could also define an abstract Startable class that implements the IStartable and have all Startable (IStartable implementations) classes derive from that abstract base class which would allow your Startables to inherit the Start() method from the base class and not have to explicitly define that method for each implementation of IStartable.


It's me Tobias btw, lost my old password for that account.

New Post: Windows Store sample?

$
0
0
I'm having a hard time finding MEF code samples anywhere. I'm working on a Windows Store application and would like the UI to be somewhat modular. My plan is to define a general layout and load various modules into different sections, each module implementing the same interface. It seems like MEF is the thing for this, but the code sample on MSDN is a console app. The "meflook" sample on this codeplex site seems helpful, but I'm not sure where to download it. It's not included it any of the source or binary downloads here, as far as I can see.

New Post: MEF2 with MVC4 via Microsoft.Composition

$
0
0
I am a bit confused as to what is the best option for utilizing MEF in and MVC 4 application.

Kenny, your solution seems to use the "older" version of MEF and not the lighter weight Microsoft.Composition nuget project. (unless I am completely confused and the new code is in .net 4.5??)

http://nuget.org/packages/microsoft.composition

What is gained by using the newer nuget project if any?

I currently have my project utilizing the mvc integration providing by the now out of date MefContrib.MVC project (https://github.com/MefContrib/MefContrib), which seems to be working but I am noticing a bit of overhead in production compared to my non MEF applications.

Does .net 4.5 include some of the new MEF 2 code? I find the whole MEF project(s) confusing even the home page for this project says to use the original MEF found in .net and not this project but then in the next box says to use the fully supported Microsoft.Composition which is it?

(from home page)
Important: this site hosts source code for unsupported, pre-release versions of MEF. If you want to use MEF in production, you should strongly consider using the supported versions included in the .NET Framework and Silverlight.

.NET 4.5 and Windows 8 Store apps can now install the fully-supported, lightweight Microsoft.Composition package from NuGet.
So in summary my question is:

If I am going to start a brand new asp.net project using MVC 4, WebAPI and MEF what project should I use and what is the best current example?

Created Issue: Plugin can't deserialize -? [14606]

$
0
0
Hi,

I've developed a plugin for my MEF application, and it uses it's own serialize / deserialize utility for persisting state data (BinaryFormatter). On it's own outside of MEF, the plugin project works fine. However, when working with the MEF host, the plugin serialization util fails. While the plugin is able to serialize objects, when it tries to deserialize them (e.g., on the next line of code) it fails. The exception is that it is "unable to find assembly..." and the assembly it can't find is it's self !!!!

By the way, the test object that was serialized is a dummy defined within the plugin project. No issues here. And, MEF solution, apart from this issue, seems to be working fine - Assemblies found, export/imports resolved.

I'm new to MEF and so unsure what the problem is. Any thoughts appreciated.

Thanks!
wak

Commented Issue: WP8 support missing in PCL assemblies! [14603]

$
0
0
Since Windows Phone 8 is not checked as supported target framework in the MEF portable class libraries (currently only .NET for Windows Store apps and .NET Framework 4.5), it will only work in emulator and not on a physical device. So in order to be able to share code between WinRT and WinPRT you have to rebuilt the MEF source yourself, with added support for WP8.

Since the solution is as simple as that I hope there will be a release very soon, with common PCLs targeting all of the above, thus enabling shared assemblies between Windows Store apps and Windows Phone 8 apps for example.
Comments: +1

New Post: MEF Container Initialization

$
0
0
I have a problem initializing MEF. I built an application that uses MEF and it seems to work fine on a WIndows 8 and Windows 7 SP1 machines. However, when I run the application on a third machine (windows 7 SP1) I get a ImportCardinalityMismatchException during the container.Compose method. I don't know why the application runs fine on two machines and on another it does not. Any suggestions? Here is my initialization:
        private void ComposeMef()
        {
            var catalog = new AggregateCatalog(
                    new DirectoryCatalog("."),
                    new AssemblyCatalog(Assembly.GetExecutingAssembly()));

            var batch = new CompositionBatch();
            batch.AddPart(this);

            _container = new CompositionContainer(catalog);
            _container.Compose(batch);
        }

New Post: MEF Container Initialization

$
0
0
I figured it out. The third machine was missing an updated library (.dll) that had the export

New Post: Consume Plugin in MFC App

$
0
0
We have a legacy MFC application that needs to consume some plugins based on MEF. How do I go after doing this? The plugin is displaying a screen, passing back some images and text.

New Post: Reloading an updated version of XAP through DeploymentCatalog does not recompose correctly

$
0
0
The reason is related to how silverlight handles loading modules in app domains, it does not allow more than one version of a dll so it ignores new version until you restart your application.

Hope this helps,


From: [email removed]
To: [email removed]
Date: Wed, 27 Feb 2013 11:29:53 -0800
Subject: Re: Reloading an updated version of XAP through DeploymentCatalog does not recompose correctly [MEF:404786]

From: highdownts
Did you ever solve this issue? I am going down a similar path with switching to MEF instead of Prism to download modules. Thanks...
Read the full discussion online.
To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)
To start a new discussion for this project, email MEF@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

New Post: Reloading an updated version of XAP through DeploymentCatalog does not recompose correctly

$
0
0
Thanks for sharing your results.

Doesn't this create a real-time issue when customers have persisted login enabled and leave their browser open for several days. If a server update occurs with new MEF related dlls, does this cause the user to experience somewhat unpredictable application failures? I will try to reproduce your issue to see what happen.

Regards...

New Post: Use MEF to allow only 2 instances at max per application

$
0
0
I am using MEF as an IOC in my application. I found myself stuck in a situation where I need exactly two instance at a time for a class in my application (across all threads). I thought it would be easy just by adding export attribute twice with different container name and then using that container name to create two instances.
[Export("Condition-1",typeof(MyClass)]
[Export("Condition-2",typeof(MyClass)]
[PartCreationPolicy(System.ComponentModel.Composition.CreationPolicy.Shared)]
public class MyClass  {   }
And then get export as
Container.GetExport<MyClass>("Condition-1").Value
Container.GetExport<MyClass>("Condition-2").Value
But this trick did not work. CreationPolicy is ignoring the ContractName and is returning one instance no matter what contract name i use in GetExport. I finally able to solve my problem by using CompsositionBatch
cb.AddExportedValue<MyClass>("Condition-1",new MyClass());
cb.AddExportedValue<MyClass>("Condition-2",new MyClass());
But my question is, Why am I not able to get different instances on the basis of Contract Name. Is it right that Contract name does not matter if CreationPolicy is shared?

New Post: Use MEF to allow only 2 instances at max per application

$
0
0
Hi there,

Creation policy (e.g. sharing) applies to parts, while one part may have many exports. This is just how the MEF component model works - in most situations this turns out to be useful.

To achieve what you want in a more MEF-like way:
  1. Don't make MyClass a part at all:
public class MyClass { }
  1. Create a separate class that holds and exports the two instances as properties:
public class MyClassConfig
{
   MyClass _inst1 = new MyClass();
   MyClass _inst2 = new MyClass();

   [Export("Condition-1")]
   public MyClass Inst1 { get { return _inst1; } }

   [Export("Condition-2")]
   public MyClass Inst2 { get { return _inst2; } }
}
This is the basic approach, anyway - you can tinker with MyClassConfig to implement lazy construction etc. if this is needed.

Hope this simplifies things!
Nick

New Post: What are all the cases that make an [ImportingConstructor] not load?

$
0
0
I posted this question on stackoverflow.

Basically an [ImportingConstructor] is failing to load, then when I allow a specific part to be default, the constructor it is able to load. The confusing part to me is that this value is properly hydrated. It would make sense to me if it came in as default because it would be a sign that my part composition was off.

Looking into it farther, it does not seem to have anything to do with a deep circular reference, since I have tested with that part having no dependencies of its own.

What are the possible causes for this type of behavior?

New Post: SQL database in a MEF application

$
0
0
This question is not geared towards an implementation of MEF per se, but suppose I have a WPF application whose features are dynamically composable through MEF. The application is also backed by a SQL database. There are tables and stored procedures that are feature specific, and there are some that are shared across all features...

Should the database always contain all of the supporting objects for all features regardless of whether they are dynamically composed in an instance of the application? I think that would certainly work and be the easiest solution, but is anyone doing anything different?

Any advice is appreciated.
Viewing all 265 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>