windows - 使用自定义 .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 版本并针对最新的版本,但错误仍然存在。
解决方案
发生这种情况是因为 WinRT API 仅在构建到通用 Windows 平台时可用,而在 Unity 编辑器中不可用。在使用 Windows 运行时的 API 时,建议有条件地使用预处理器指令 ENABLE_WINMD_SUPPORT 定义包含任何利用 WinRT 的代码。
有关如何在 Unity 项目中为 HoloLens 使用 WinRT API 的更多信息,请参阅此处:WinRT APIs with Unity for HoloLens
推荐阅读
- reactjs - 从 export const 调用类函数 react native
- react-native - react-native 应用程序的 assembleRelease 版本在启动时崩溃
- javascript - 在 ReactJs 中使用带有 setState 的 onclick 功能时,如何传递参数?
- powershell - 传递 Cmdlet 名称和参数的 Invoke-Command 包装函数
- html - 在移动浏览器中隐藏工具栏时使高度为 100%
- docker - 直接挂载的 NFS 卷上的 persistentVolumeReclaimPolicy - kubernetes
- javascript - 开玩笑抛出错误>类型错误:无法读取属性'user_env_variable是未定义的
- python - 从网页收集并打印事件标题
- android - 带有标签和 ViewPager 的 Android AppBarLayout
- php - laravel 500 错误:此页面无法正常工作