Aug 9, 2009 at 10:51 PM
Edited Aug 9, 2009 at 11:02 PM
I started fiddeling today with this IoC and Dependency injection etc in my WPF apps using MEF. Great stuff.
I got the basic concept working nicely. Then I changed my catalog to a AggregateCatalog so that I could included the directory "Plugins". I then created a new C# class library project and implemented my little test interface there. With everything
exported nicely etc. the dll is ready to be used as a "plugin" ( or extension or whatever you want to call it ). Now. I manually copied this file into a Plugins directory that I created in the Debug (or bin) folder.
Ok so we are ready to go. I launch my application from VS and bam there pops this weird Visual Studio window that says: "The following module was built either with optimizations or without debug information. C:\Users\zool\documents\...\bin\debug\plugins\yourstringfactory.dll"
followed by some useless information about changing my dll's build configuration to debug (which it is) OR to disable the message with the 'Warn if no user code on launch' option. (which I cannot find)
So the DirectoryCatalog is trying to load the DLL, but it fails to load any files or parts resulting in the ImportCardinalityMismatchException later on when everything is glued together. Unlucky.
So I tried many different things, including loading the application .exe itself (which also contain the exports) and that worked. So I could get the parts from my application assembly just fine, but not some other assembly I created.
Ok I kind of resolved that issue. The Visual Studio Window was caused because I did not copy the debug .pdb file with the dll. The second ImportCardinalityMismatchException was caused because the parts were, well, broken or something.
So that leads to my next question:
The parts that fit together. Must they be in the same assembly or map 1 to 1 or something? I ask because in my .exe I have a dependent and a property. I added the plugin folder to my catalog that results in another property to load. Therefore, my catalog
has 3 parts: 1 dependent and 2 properties. Both properties satisfy the dependent.
CompesitionContainer.GetExport fails with such a catalog when trying to glue things togeher.
My question is: Is this working as intended? Can CompesitionContainer not determine which of the 2 properties it should use to complete the dependent?