除非我引用的项目

除非我引用的项目

本文介绍了无法加载的WinRT组件,除非我引用的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的问题。我创建了一个使其可用于.NET一些传统的C / C ++代码通过一些C#包装类在Windows运行时组件(适用于Windows应用商店)。

I'm running into an odd problem. I created a Windows Runtime Component (for Windows Store) that makes some legacy C/C++ code available to .NET via some C# wrapper classes.

我写了一个测试工具商店应用程序(以下简称测试1)引用WRC的项目的(在同一个解决方案,这两个项目)。它调用到组件,一切工作正常。

I wrote a test harness Store App (hereafter referred to as "test1") that references the WRC project (both projects in the same solution). It calls into the component and everything works fine.

接下来,我把下面的输出文件从WRC项目:

Next I take the following output files from the WRC project:

MyWrtComponent.dll
MyWrtComponent.exp
MyWrtComponent.pdb
MyWrtComponent.pri
MyWrtComponent.winmd

...并尝试从另一个商店应用工程(测试2)中使用它们。在这个项目中,而不是引用MyWrtComponent项目,我添加到.winmd文件的引用。一切都建立很好,但是当我运行应用程序TEST2我只要我尝试使用MyWrtComponent实施了C#类之一得到的mscorlib一个System.IO.FileNotFound异常:

...and try to use them from another Store app project ("test2"). In this project, instead of referencing the MyWrtComponent project, I add a reference to the .winmd file. Everything builds fine, but when I run the test2 app I get a System.IO.FileNotFound exception from mscorlib as soon as I try to use one of the C# classes implemented in MyWrtComponent:

at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
at MyWrtComponent.MyWrtClass..ctor()

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



使用版本主场迎战MyWrtComponent没有按的调试版本。'T作任何区别

Using release vs. debug build of the MyWrtComponent doesn't make any difference.

在test2的运行procmon中,我看到在装货vccorlib120_app.DLL几次不成功的尝试(或vccorlib120d_app.DLL如果我建立调试):

Running ProcMon on test2, I see several unsuccessful attempts at loading vccorlib120_app.DLL (or vccorlib120d_app.DLL if I'm building debug):

QueryOpen   F:\test2\bin\Debug\AppX\vccorlib120d_app.DLL    NAME NOT FOUND
QueryOpen   F:\test2\bin\Debug\AppX\vccorlib120d_app.DLL    NAME NOT FOUND
CreateFile  C:\Windows\SysWOW64\vccorlib120d_app.DLL    NAME NOT FOUND

我确认这文件不我的存在C:\Windows\SysWOW64文件夹中。我不知道这是否是有关我的问题。

I've confirmed that this file doesn't exist in my C:\Windows\SysWOW64 folder. I don't know whether that's relevant to my problem.

当我运行测试1,不同的地点进行搜索,并找到该文件:

When I run test1, different locations are searched, and the file is found:

QueryOpen   F:\test1\bin\Debug\AppX\vccorlib120d_app.DLL    NAME NOT FOUND
CreateFile  C:\Program Files\WindowsApps\Microsoft.VCLibs.120.00.Debug_12.0.20827.3_x86__8wekyb3d8bbwe\vccorlib120d_app.dll SUCCESS

我比较了两个测试项目的bin\Debug\AppxManifest.xml,并注意到一个重要的区别; test1的有以下和TEST2不会:

I compared the bin\Debug\AppxManifest.xml of both test projects, and noticed one important difference; test1 has the following and test2 doesn't:

<Dependencies>
  <PackageDependency Name="Microsoft.VCLibs.120.00.Debug" MinVersion="12.0.20827.3" />
</Dependencies>

如果我这三个行添加到测试2中生成的输出和运行应用程序,它的工作原理,但当然,这不是一个真正的解决。

If I add these three lines to the generated output of test2 and run the app, it works, but of course that's not a real fix.

有谁知道这是怎么回事呢?是否有MyWrtComponent,不知怎的,没有被传达的依赖,或者我应该做些什么来包装vccorlib120d_app.DLL与我运行时组件一起,还是...?

Does anyone understand what's going on here? Does MyWrtComponent have a dependency that somehow isn't being communicated, or am I supposed to do something to package vccorlib120d_app.DLL along with my runtime component, or ... ?

在此先感谢。

推荐答案

好吧,你运行到这里的几个问题,第一个是,作为您的WinRT组件使用C ++,你需要要在您的应用程序到Microsoft Visual C ++运行包的参考,这是后话,预计由组件(应用程序开发者)的最终用户做的,所以要做到这一点,右键单击引用在Solution Explorer文件夹该应用程序并进入Windows的>扩展,可以从可用的SDK的列表中选择Microsoft Visual C ++运行包,然后单击确定。

Well, you're running into several issues here, the first one is that as your WinRT component uses C++, you need to have a reference to the Microsoft Visual C++ Runtime Package in your app, this is something that is expected to do by the end user of your component (the app developer), so to do it, right click the References folder in the Solution Explorer of the app and go to Windows->Extensions, there select Microsoft Visual C++ Runtime Package from the list of available SDKs and click Ok.

第二,如果你打算保持此组件为自己,最好您引用的项目,因为它是应该做的更简单的方法,如果您打算发布它,那么你需要创建一个SDK,以确保所有的作品都在一起,注意,这是必要的C ++的WinRT组件,而不是C#或VB.NET的组件,原因似乎是C ++的WinRT组件被分裂成元数据(WinMD文件),实现(DLL文件),即使你把它们并排他们无法识别对方,而在C#和VB.NET中的元数据和实现都在同一个文件(WinMD)。如果你想创建一个SDK,然后阅读本文档 MSDN上。

Second, if you plan to keep this component for yourself, it's better that you reference the project as it's the easier way to do, if you plan to distribute it, then you need to create a SDK to be sure that all the pieces are together, note that this is necessary for C++ WinRT components, but not for C# or VB.NET components, the reason seems to be that C++ WinRT components are splitted into metadata (WinMD file) and implementation (DLL file), and even if you put them side by side they're unable to recognize each other, while in C# and VB.NET the metadata and its implementation are on the same file (WinMD). If you want to create an SDK, then read this documentation on MSDN.

这篇关于无法加载的WinRT组件,除非我引用的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!