none
MEF Question: Troubleshooting why Import is not importing when Export is exporting RRS feed

  • Question

  • This might sound a strange design to some. But this is what I am trying to do.

    Assembly A Exports Part P.

    Assembly A Imports Part P in one of its classes (note that same assembly exports it).

    Assembly B is MEF Helper assembly which has a class that holds the CompositionContainer with all necessary catalogs.

    A references B to call the MEF Helper classes.

    The class in Assembly A that imports part P, calls on Assembly B's helper class; it calls the method FillMeWithParts(object target)

    in the target parameter it provides this reference. 

    FillMeWithParts() is defined as follows

            public void FillMeWithParts(object target)
            {
                //Fill the imports of this object
                try
                {
                  
                    this._container.ComposeParts(target);
                }
                catch (CompositionException compositionException)
                {
                    Console.WriteLine(compositionException.ToString());
                }
                catch (Exception Exception)
                {
    
                }
            }

    Here is the problem. The parts aren't imported. The DirectoryCatalog supplied in Helper assembly (B) does have correct directory for Assembly A.

    What could be the issue ?


    Fahad

    Wednesday, March 19, 2014 9:28 PM

Answers

  • Hi Fahad,

    The .NET assembly loader is unable to find 2.1.30214.0. It can’t find the assembly that was referenced. Mark sure it can find the right assembly by putting it in the GAC or in the application path. http://blogs.msdn.com/b/junfeng/archive/2004/03/25/95826.aspx.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 21, 2014 7:16 AM
    Moderator

All replies

  • Hi Fahad,

    Export and import are easily setting, I can see of that will go wrong is the setting of Catalogs. You put part p and call helper class in assembly A. I assume you forget to add AssemblyCatalog. Try the following code:

    var catalog = new AggregateCatalog();
    
    catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));
    

    If this doesn’t work, please post a whole project here using SkyDrive to help me troubleshooting.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 20, 2014 3:19 AM
    Moderator
  • I cannot share my actual project with you due to my agreement with the company. I tried creating the same situation through a sample project but I couldn't. This one refelects the model I have but it works. I am starting to pull my hairs out.

    https://www.dropbox.com/s/7ayssnclczo32j0/MEFTest.zip

    Also, in my actual solution at ComposeParts() method call, I am seeing tons of TypeLoadException (s)  but they are all handled. Most of them are on System.Reactive.Interfaces.dll


    Fahad



    • Edited by Fahad349 Thursday, March 20, 2014 7:19 AM
    Thursday, March 20, 2014 7:05 AM
  • I am beginning to think its not MEF's fault. It has to do with ReactiveUI possibly.

    {System.IO.FileLoadException: Could not load file or assembly 'System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    File name: 'System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

    === Pre-bind state information ===
    LOG: User = fahadash-PC\fahadash
    LOG: DisplayName = System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
     (Fully-specified)
    LOG: Appbase = file:///C:/path/to/project/src/Debug/
    LOG: Initial PrivatePath = NULL
    Calling assembly : ReactiveUI, Version=5.5.0.0, Culture=neutral, PublicKeyToken=null.
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: C:\Users\fahadash\AppData\Local\Quant Technologies\QuantTechnologies_Shell_Vs\1.0\QuantTechnologies.Shell.Vs.exe.config
    LOG: Using host configuration file: 
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
    LOG: Post-policy reference: System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    LOG: Attempting download of new URL file:///C:/path/to/project/src/Debug/System.Reactive.Interfaces.DLL.
    LOG: Attempting download of new URL file:///C:/path/to/project/src/Debug/System.Reactive.Interfaces/System.Reactive.Interfaces.DLL.
    LOG: Attempting download of new URL file:///C:/path/to/project/src/Debug/Extensions/Application/System.Reactive.Interfaces.DLL.
    WRN: Comparing the assembly name resulted in the mismatch: Minor Version
    ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
    }
    Fahad

    • Edited by Fahad349 Thursday, March 20, 2014 7:39 AM
    Thursday, March 20, 2014 7:37 AM
  • Hi Fahad,

    The .NET assembly loader is unable to find 2.1.30214.0. It can’t find the assembly that was referenced. Mark sure it can find the right assembly by putting it in the GAC or in the application path. http://blogs.msdn.com/b/junfeng/archive/2004/03/25/95826.aspx.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 21, 2014 7:16 AM
    Moderator