0x8007007E 仅在 Windows Phone 目标中

0x8007007E only in Windows Phone target

我的目标是具有 UWP C++ 通用 Windows 项目参考的 C# 应用程序,它位于同一解决方案中。此应用程序在 Windows 桌面上正常运行,没有任何错误,但是当我尝试在 Windows Phone 设备上 运行 它时,我收到以下错误:

System.IO.FileNotFoundException: The specified module could not be found. >(Exception from HRESULT: 0x8007007E)
   at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
   at *CALLED METHOD HERE*
   at Demo.MainPage..ctor()'Demo.exe' (Win32): Loaded

我检查了 csproj 看它是直接引用 wincmd 文件还是 dll 但它确实引用了另一个项目。

我已尝试检查设备存储,但找不到一种方法来浏览设备中已部署的应用程序内容。

目标平台version/min.版本:10.0.14393.0

编辑 1:

看起来问题是生成的 DLL 正在引用 ucrtbased.dll

File Type: DLL

  Image has the following dependencies:

    api-ms-win-core-com-l1-1-1.dll
    api-ms-win-core-debug-l1-1-1.dll
    api-ms-win-core-synch-l1-2-0.dll
    api-ms-win-core-synch-l1-2-1.dll
    api-ms-win-core-sysinfo-l1-2-1.dll
    vccorlib140d_app.DLL
    MSVCP140D_APP.dll
    ADVAPI32.dll
    VCRUNTIME140D_APP.dll
    ucrtbased.dll
    api-ms-win-core-winrt-string-l1-1-0.dll
    api-ms-win-core-util-l1-1-0.dll
    api-ms-win-core-winrt-error-l1-1-1.dll
    api-ms-win-core-handle-l1-1-0.dll
    api-ms-win-core-errorhandling-l1-1-1.dll
    api-ms-win-core-string-l1-1-0.dll
    api-ms-win-core-processthreads-l1-1-2.dll
    api-ms-win-core-winrt-l1-1-0.dll
    api-ms-win-core-profile-l1-1-0.dll
    api-ms-win-core-libraryloader-l1-2-0.dll
    api-ms-win-core-interlocked-l1-2-0.dll
    api-ms-win-core-heap-l1-2-0.dll
    api-ms-win-core-memory-l1-1-2.dll

编辑 2:

Visual Studio 包含 ucrt/arm 路径作为库路径。我正在使用 Visual Studio 2017

LibraryPath = C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\VC\Tools\MSVC.10.25017\lib\ARM\store;;C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\VC\Tools\MSVC.10.25017\atlmfc\lib\ARM;;C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\VC\Auxiliary\VS\lib\ARM;;C:\Program Files (x86)\Windows Kits\lib.0.14393.0\ucrt\arm;;;C:\Program Files (x86)\Windows Kits\lib.0.14393.0\um\arm;C:\Program Files (x86)\Windows Kits\NETFXSDK.6.2\lib\um\arm;;C:\Program Files (x86)\Windows Kits\NETFXSDK.6.1\Lib\um\arm

编辑 3:

出于某种原因,_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1 似乎是从允许 ARM 目标(所有项目)访问桌面 API 的某个地方继承的。这会导致问题吗?

编辑 4: 使用 dumpbin /imports 我可以得到我的程序正在使用的 ucrtbased.dll 函数的列表,其中大部分是标准库函数:

ucrtbased.dll
          10D0E7E4 Import Address Table
          10D0F430 Import Name Table
                 0 time date stamp
                 0 Index of first forwarder reference

              527 strcpy_s
              523 strcat_s
               69 __stdio_common_vsprintf_s
              3B2 _wsplitpath_s
              55F wcscpy_s
              396 _wmakepath_s
              174 _initterm_e
              33C _wassert
              175 _invalid_parameter
                5 _CrtDbgReportW
              562 wcslen
              52C strlen
              47F free
              4DC mbstowcs_s
              526 strcpy
              53A strtol
               CD _difftime64
              296 _mktime64
               6A __stdio_common_vsscanf
              575 wcstombs
              500 realloc
              3C2 _wtoi
              54F toupper
               36 __acrt_iob_func
              173 _initterm
              4FE rand
              410 ceil
              44A exit
              166 _gmtime64_s
              318 _time64
              4D3 malloc
               E0 _errno
              3D0 abort
              52F strncmp
              12C _ftime64
              55C wcscmp
              11D _free_dbg
              203 _malloc_dbg
                4 _CrtDbgReport
               A2 _callnewh
              2BD _seh_filter_dll
               B7 _configure_narrow_argv
              170 _initialize_narrow_environment
              171 _initialize_onexit_table
              2B1 _register_onexit_function
               E6 _execute_onexit_table
               C3 _crt_atexit
               C2 _crt_at_quick_exit
               A5 _cexit
               5D __stdio_common_vfprintf

目前怀疑:使用ADVAPI32.dll依赖

所以这是我堆栈中的罪魁祸首:ADVAPI32.dll。

我使用的是加载 SystemFunction036 (RtlGenRandom) 的依赖项,解决方案是重新编写代码以使用具有相同功能的等效 UWP 函数。

Microsoft 真的应该重新考虑他们向开发人员报告此类问题的方式,因为异常似乎与该问题完全无关。一个简单的异常表明 ADVAPI32.dll 是加载 UWP 移动版本中不允许的函数的罪魁祸首。由于这是一个运行时问题,您的代码可以正常编译,除非您测试它,否则您永远不知道您的代码无法运行。