简体   繁体   English

从C#加载C ++ Windows运行时组件时发生异常

[英]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.

相关问题 C#和C ++之间的Windows(电话)运行时组件流 - Windows (Phone) Runtime Component stream between C# and C++ UWP C# 和 Windows 运行时组件 C++ 打开文件时出现权限被拒绝错误 - UWP C# and Windows Runtime Component C++ Permission Denied error when opening file Windows Universal-在C ++项目中调用C#运行时组件时崩溃 - Windows Universal - crashes when calling C# runtime component in C++ project 如何用C#编写的类库引用用C ++编写的Windows运行时组件? - How can Windows Runtime Component written in C++ be referenced from Class Library written in C#? 加载表单时C ++ / CLI / C#BadImageFormat异常 - C++/CLI/C# BadImageFormat Exception when loading form 从C#.NET Windows应用程序调用C ++ dll时出现运行时错误 - runtime error when calling a C++ dll from C# .NET windows application 如何将对象从JavaScript传递到Windows运行时组件C#? - How to pass object from JavaScript to Windows Runtime Component C#? 从C#调用C ++ dll时的C#和C ++,运行时错误 - C# & C++, runtime error when call C++ dll from C# 如何将C ++ / CX内置的Windows运行时组件安装到C#项目中? - How do you install a Windows Runtime Component built in C++/CX into a C# project? How to import C++ Legacy DLL in C# UWP application without Windows Runtime Component - How to import C++ Legacy DLL in C# UWP application without Windows Runtime Component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM