首页 > 解决方案 > 使用自定义 .dll 文件会产生 Unable to resolve reference 'Windows.Foundation.UniversalApiContract' 和其他错误

问题描述

我目前正在为 Hololens 2 开发 Unity 应用程序。这里我想通过蓝牙向 Hololens 发送数据。为此,我制作了一个小型蓝牙库并将其编译为 .dll 文件。然后我尝试将此 .dll 文件导入到我的资产中,但出现多个错误:

Unable to resolve reference 'Windows.Foundation.UniversalApiContract'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Windows.Foundation.FoundationContract'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'System.Runtime.WindowsRuntime'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.

我已经更新了 SDK 版本并针对最新的版本,但错误仍然存​​在。

标签: windowsunity3ddllbluetoothhololens

解决方案


发生这种情况是因为 WinRT API 仅在构建到通用 Windows 平台时可用,而在 Unity 编辑器中不可用。在使用 Windows 运行时的 API 时,建议有条件地使用预处理器指令 ENABLE_WINMD_SUPPORT 定义包含任何利用 WinRT 的代码。

有关如何在 Unity 项目中为 HoloLens 使用 WinRT API 的更多信息,请参阅此处:WinRT APIs with Unity for HoloLens


推荐阅读