locked
How to get a C++/CLI component to load into MEF? RRS feed

  • Question

  • Having seen the similar question https://social.msdn.microsoft.com/Forums/en-US/157dc66e-87a9-44bf-9de9-9fcdc6c95fea/ccli-how-to-translate-ltexportgettypeiplugingt?forum=netfxbcl here, I've double checked that all DLLs and the executable target the same processor type and framework version.  Looking at a C# component and the problematic C++/CLI component in ILSpy, I cannot discern a problem with the interface implementation and its attributes (other than one method being declared unsafe, because it uses for each).

    Note the multiply on the left is written in C#, the divide on the right is written in C++/CLI

    I loaded the assembly explicitly into the MEF catalog, but the ComposeParts extension method will not include the component written in C++/CLI into the component store.

    I can upload the entire project if desired, it is based on the sample given in the MEF page of docs.microsoft.com.  

    Wednesday, July 8, 2020 9:31 PM

All replies

  • Hi eric.t,

    Thank you for posting here.

    Here's the example of using MEF to export the C + + cli interface:

    Is it possible to Export a C++ CLI interface with MEF and Prism

    If the code in the reference cannot help you solve the problem, please provide a sample that can help us reproduce your problem. It will help us make a test.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 9, 2020 3:06 AM
  • Hi, unfortunately that example is only the interface in C++, not the implementation.  I have a project (at https://powersoft365-my.sharepoint.com/:u:/g/personal/erict_powersoft_ca/Eeb2RCN38npBqZEFmYKBU9ABof8G6qeEsxRQ1fBcQNT7xA?e=hD9ong) derived from a CodeProject article (https://www.codeproject.com/Articles/432069/Simple-MEF-Application-for-Beginners). The code in this project implemented three different mathematical operations (+, -, *) as separate extensibility objects, along with an importing assembly, and an interface definition assembly. 

    I added proper Disposing in the importing assembly as well as a fourth extensible object (division) - this one written in C++/CLI.  Yet I can't get the division to get imported.  

    I appreciate any assistance you can give.

    PS: I found one possible explanation in https://stackoverflow.com/questions/44051629/import-c-cli-dll-using-mef where the accepted answer states that C++/CLI cannot be used to load extensibility objects, but would really like to see an official answer.

    Monday, July 13, 2020 9:11 PM
  • Hi eric.t,

    Make sure the dll from C++/CLI has been successfully generated.

    Since I cannot test the C++/CLI project, you can also post your question in Developer Community for more help.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 15, 2020 9:00 AM
  • As the ILSpy image at the top of this thread shows, the DLL generated successfully. I can also load the assembly and assign it to the interface explicitly.

    I'll give the Developer Community a shot.  Thanks for your help.

    By the way - why does your signature say "Wicresoft"?


    • Edited by eric.t Wednesday, July 15, 2020 2:10 PM
    Wednesday, July 15, 2020 2:09 PM