locked
[UWP]Exception when loading C++ Windows Runtime Component from C# RRS feed

  • Question

  • I am running into an issue where my UWP app is in C# but it utilizes a Windows Runtime Component C++ Dll that is in the same solution. When I run my app in Debug I see no issues. But when I run in Release (x86) I get the following exception (occurs in VS debbuger):

    The specified module could not be found. (Exception from HRESULT: 0x8007007E

       at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
       at CppFunction
       at CsharpFucntion()
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()

    My C++ component does link with oppenssl (Which I manually built from the microsoft github page).  I already tried to rebuild the openssl components just to see if that was the issue, but it did not help.

    I also verified that the DLL and WINMD files are present in the bin\x86\Release\AppX folder


    Thursday, January 14, 2016 3:12 PM

Answers

  • After a few days of exploring, I finally figured out the issue. Our team has multiple UWP apps that we are building and we have some common solutions that we build DLLs that get used by all apps.

    One of the common projects was building a non-Windows Runtime C++ DLL (Windows Universal). In the C++ Windows Runtime component in my solution, we were statically linking to the .lib file that gets created when building the mentioned DLL, and then when we package the app, we would manually include the DLL.

    For some reason, this method seemed to work fine in most of the targets, except the x86 / Release target.

    Solution: Create a Static Library project that contains all the code files from the common DLL and link against the new static library instead.

    • Marked as answer by Michael Sabin Friday, January 15, 2016 8:29 PM
    Friday, January 15, 2016 8:29 PM

All replies

  • Hello Michael Sabin,

    1. Since you are using C++ Runtime Component Do you have reference for the Microsoft Visual C++ Runtime Package in your app?

    Please see this similar issue.

    http://stackoverflow.com/questions/19555318/cant-load-winrt-component-unless-i-reference-the-project

    Could you also try to provide a minimum sample in which this issue is reproducible?

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, January 15, 2016 8:35 AM
  • After a few days of exploring, I finally figured out the issue. Our team has multiple UWP apps that we are building and we have some common solutions that we build DLLs that get used by all apps.

    One of the common projects was building a non-Windows Runtime C++ DLL (Windows Universal). In the C++ Windows Runtime component in my solution, we were statically linking to the .lib file that gets created when building the mentioned DLL, and then when we package the app, we would manually include the DLL.

    For some reason, this method seemed to work fine in most of the targets, except the x86 / Release target.

    Solution: Create a Static Library project that contains all the code files from the common DLL and link against the new static library instead.

    • Marked as answer by Michael Sabin Friday, January 15, 2016 8:29 PM
    Friday, January 15, 2016 8:29 PM
  • Hi Michael!

    I have faced the same problem as you mentioned above.

    Could you explain a bit more how did you solve this issue? 

    Especially the part of linking WinRT component to the static library inside the app package (I can't figure out what path should I use to link to the app installation dir)

    Thanks

    Monday, September 26, 2016 1:12 PM
  • It's been a while, so I don't exactly remember...  But to link the static library, In you C++ Universal component, you specify the name of the .lib file (Linker -> Input) and in the VC++ Directories specify the path to where the lib resides.
    Monday, September 26, 2016 1:53 PM
  • Thanks for a quick reply Michael! 

    Do you remember if you used /md or /mt target library?

    >> specify the name of the .lib file (Linker -> Input) and in the VC++ Directories specify the path to where the lib resides.

    it works fine in the /md case but in case of /mt I'am forced to reference to the libcmt.lib which located in $(VC_ReferencesPath_VC_x86) and then I got an error as you've mentioned above. Do you remember if you had the same issue?



    Tuesday, September 27, 2016 10:19 AM
  • Using /MD for the DLL that links the static lib...
    Tuesday, September 27, 2016 2:23 PM