简体   繁体   中英

Exception when loading C++ Windows Runtime Component from C#

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM