[英]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. 我遇到一个问题,其中我的UWP应用程序使用C#,但是它利用了同一解决方案中的Windows运行时组件C ++ Dll。 When I run my app in Debug I see no issues.
当我在Debug中运行我的应用程序时,我看不到任何问题。 But when I run in Release (x86) I get the following exception (occurs in VS debbuger):
但是,当我在Release(x86)中运行时,出现以下异常(在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). 我的C ++组件确实与oppenssl链接(我是从microsoft github页面手动构建的)。 I already tried to rebuild the openssl components just to see if that was the issue, but it did not help.
我已经尝试重建openssl组件,只是为了查看是否是问题所在,但这没有帮助。
I also verified that the DLL and WINMD files are present in the bin\\x86\\Release\\AppX folder 我还验证了bin \\ x86 \\ Release \\ AppX文件夹中是否存在DLL和WINMD文件
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.
我们的团队拥有多个正在构建的UWP应用程序,并且我们拥有一些通用的解决方案,可以构建供所有应用程序使用的DLL。
One of the common projects was building a non-Windows Runtime C++ DLL (Windows Universal). 常见的项目之一是构建非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.
在我的解决方案的C ++ Windows运行时组件中,我们静态链接到在构建提到的DLL时创建的.lib文件,然后在打包应用程序时,我们将手动包含DLL。
For some reason, this method seemed to work fine in most of the targets, except the x86 / Release target. 由于某种原因,该方法似乎在大多数目标中都可以正常工作,但x86 / Release目标除外。
Solution: Create a Static Library project that contains all the code files from the common DLL and link against the new static library instead. 解决方案:创建一个包含来自公共DLL的所有代码文件的静态库项目,然后链接到新的静态库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.