c# - 0x8007007E 仅在 Windows Phone 目标中

标签 c# c++ uwp windows-10-universal

我的目标是具有 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 但它确实引用了另一个项目。

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

目标平台版本/最低版本: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 Studio\2017\Enterprise\VC\Tools\MSVC\14.10.25017\lib\ARM\store;;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.25017\atlmfc\lib\ARM;;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\VS\lib\ARM;;C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\ucrt\arm;;;C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\um\arm;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.2\lib\um\arm;;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\Lib\um\arm

编辑 3:

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

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

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 移动版本中不允许的函数的罪魁祸首。由于这是一个运行时问题,您的代码可以正常编译,除非您测试它,否则您永远不知道您的代码将无法运行。

关于c# - 0x8007007E 仅在 Windows Phone 目标中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43678317/

相关文章:

c++ - 如何在 qt 中重启应用程序?

c++ - QMediaPlayer 在 QtCreator 外部启动时无法在 Windows 上开始播放

c# - UWP App 不显示图片

c# - 在 C# 中使用 httpclienthandler 使用一个参数发布多个值

C# WPF 应用程序在开发的计算机上运行,​​但不能在其他任何地方运行

c++ - 搜索数组中的元素,复杂度优于 O(n)

c# - 虚拟机的 UWP MVVM 数据绑定(bind)(来自字符串的 textbox.text)

c# - 如何在 texture2D Unity3D 上绘制矩形

c# - 将 C# .Net 加密/解密算法迁移到 Ruby

c# - 我可以为 Windows Universal App 创建闹钟应用程序吗?