locked
Problem loading C++ component when running unittests RRS feed

  • Question

  • I have a solution (VS 2015) containing a mix of C# and C++ projects, including a handful of unittest projects. The C++ projects are referneced from C# projects. Sometimes when I run unittests from the Test Explorer, I get an error when the tests are trying to load one of the C++ dll's. The problem is sporatic - when I get the error I can in most cases just rerun the test project and it will work. However, there is one of the test Projects that I am not able to run at all. This issue also mean that I am not able to run all tests together, and Thus not able to run code coverage analysis. When press F5 and run the actual .exe file, everything works fine.

    The error that I get is this:

    MyTestInitialize threw exception. System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly '<myC++Component>.dll' or one of its dependencies. The specified module could not be found..

    Any Ideas?

    Thansk Christian

    Thursday, May 12, 2016 1:41 PM

Answers

  • Hi Christian,

    I also use different ways to troubleshoot this issue, but it still has this issue. I also user certain tool to analyze the assembly:

    https://manski.net/2011/07/hunting-dll-loading-errors/

    It seems that this issue was related to many dll files like the KERNEL32.DLL/USER32.DLL/MSCOREE.DLL/UCRTBASED.DLL and so on.

    I help you submit a connect report here:

    https://connect.microsoft.com/VisualStudio/feedbackdetail/view/2752533/problem-loading-c-component-when-running-unittests

    Maybe the report team experts could provide better response, I will follow up this connect for you. If I get any latest information, I will share it here.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

    Microsoft does not control these sites and has not tested any software or information found on these sites;

    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Jack


    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, May 27, 2016 8:25 AM

All replies

  • Hi Christian,

    >>The C++ projects are referneced from C# projects.

    >>MyTestInitialize threw exception. System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly '<myC++Component>.dll' or one of its dependencies. The specified module could not be found..

    Since the VC++ dll was added as the reference of the C# project.

    (1) Please rebuild your VC++ project, and then remove the dll from the C# project, re-add it again.

    (2) Change the .net framework version and target platform(ANY CPU/X86/X64), maybe the dll need to use the matched version 32 bit or 64 bit as your current project.

    (3) Clean and rebuild your C# project, check it again.

    Best Regards,

    Jack


    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.

    Saturday, May 14, 2016 6:19 AM
  • Thanks for your reply - unfortunately, it did not help me.

    - All my Projects (C++ and C#) are targeting .net version 4.6.1.

    - C++ Projects are targeting Win32, and C# projets x86 (I have also tried AnyCPU, no difference)

    - I have re-added references and re-built stuff a million times :-)

    Regards

    Christian

    Thursday, May 19, 2016 11:22 AM
  • Hi Christian,

    >>- I have re-added references and re-built stuff a million times :-)

    One idea is that you could check the reference's properties window, and set the "copy local=True", or you could run your VS as the admin, check it again.

    If still no help, maybe you  could share me a simple sample using one drive, I will debug it in my side.

    Best Regards,

    Jack


    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, May 20, 2016 3:07 AM
  • Hm - did not make any difference either.

    Jack - how can I send stuff to you directly?

    Thanks Christian

    Friday, May 20, 2016 7:19 AM
  • Hi Christian,

    Sorry for that I couldn't provide the Email directly, if possible, please attach your Visual Studio project, you can upload it to the one drive, and then share the download link in your post. I will download and test it in my side.

    Best Regards,

    Jack


    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, May 20, 2016 9:55 AM
  • As I am working with production code, I would prefere not to make it publicly available. :-)

    My email address is cma@ddd-diagnostics.dk - if you could get in touch I can share a link with you directly.

    Thanks Christian

    Monday, May 23, 2016 3:10 PM
  • Hi Christian,

    Sorry for that we don't provide the Email support.

    Do you have the source code for this VC++ app/library? Could you run it well if you compile it in your VS IDE?

    >>MyTestInitialize threw exception. System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly '<myC++Component>.dll' or one of its dependencies. The specified module could not be found..

    For this issue, even if it was the unit test project, my understanding it is similar to the way how to reference the VC++ DLL from the C# project.

    Maybe the following thread or blog could provide useful information for you:

    https://blogs.msdn.microsoft.com/yingqin/2013/03/13/integrate-native-c-project-with-managed-c-projects/

    http://stackoverflow.com/questions/569603/using-c-class-dll-in-c-sharp-application

    In addition, please enable all options like the following screen shot.

    Best Regards,

    Jack


    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.


    Tuesday, May 24, 2016 6:01 AM
  • All right - I managed to strip down my solution to a bare minimum that demonstrates the problem. I have placed it on OneDrive like you suggested here:

    https://onedrive.live.com/redir?resid=F3915B4465B9467A!6349&authkey=!ABNpnrnCX8ynaeU&ithint=folder%2czip

    I would realy appreciate if you would try to debug the problem.

    The solution file is located in the folder ClassLibrary1. Just build the solution and run the one unittest in the Test Explorer should demonstrate the issue.

    Btw, I tried turning on the options that you suggest above, but it did not help or give me any further insights.

    And yes, as you can see, we own the source code for both the C++ and C# libraries in question. :-)

    Thanks

    Chrisitan

    Tuesday, May 24, 2016 7:33 AM
  • Hi Chrisitan,

    I also got the same issue as yours.

    Since I could repro this issue, to get the issue confirmed and diagnose by product team, would you please create connect report for it? You will get email notification for update.http://connect.microsoft.com/VisualStudio/feedback/CreateFeedback.aspx

    If you submit a connect report, please share me the link here, I will help you vote it.

    Sincerely,

    Jack


    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.

    Wednesday, May 25, 2016 9:55 AM
  • Hm - thanks, I guess.

    However, you gave me the impression that you were in a position to debug the issue. Since that is clearly not the case, I can't help feel a bit disappointed.

    I know how to file a bug with VS - whether they want to fix it must be up to them.

    Christian

    Thursday, May 26, 2016 12:01 PM
  • Check that your C++ DLLs (and any of their dependent DLLs) are all in the same folder as the unit test build output, or their path(s) are in the PATH environment variable.

    I have had lots of problems with pure C++ unit tests and paths. I ended up having to copy all DLLs into one folder to get the unit tests to run. None of the .runsettings or .testsettings options related to deployment or assembly paths, etc. work with C++ code.

    Thursday, May 26, 2016 5:54 PM
  • Hi Christian,

    I also use different ways to troubleshoot this issue, but it still has this issue. I also user certain tool to analyze the assembly:

    https://manski.net/2011/07/hunting-dll-loading-errors/

    It seems that this issue was related to many dll files like the KERNEL32.DLL/USER32.DLL/MSCOREE.DLL/UCRTBASED.DLL and so on.

    I help you submit a connect report here:

    https://connect.microsoft.com/VisualStudio/feedbackdetail/view/2752533/problem-loading-c-component-when-running-unittests

    Maybe the report team experts could provide better response, I will follow up this connect for you. If I get any latest information, I will share it here.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

    Microsoft does not control these sites and has not tested any software or information found on these sites;

    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Jack


    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, May 27, 2016 8:25 AM