Skip to main content
 首页 » 编程设计

c#之运行时尝试查找 exe/dll 而不是 .winmd 引用

2024年02月13日11mfrbuaa

我有一个使用引用库的应用程序。 该库又引用 .winmd 库。

查看引用库的 IL,我可以看到这个引用:

.assembly extern windowsruntime FlurryWin8SDK 
{ 
  .ver 0:9:0:0 
} 

但是在运行时,我遇到了一个异常:

{"Could not load file or assembly 'FlurryWin8SDK' or one of its dependencies. The system cannot find the file specified.":"FlurryWin8SDK"} 

此外,通过使用 Procmon,我看到有人尝试搜索 FlurryWin8SDK.exe 和 FlurryWin8SDK.dll,但没有搜索扩展名为 .winmd 的文件。

此外,这是 Fusion 日志查看器的输出:

BEGIN : Framework bind. 
END   : The provided identity format is not recognized. (Exception from HRESULT: 0x80132003) 
BEGIN : Windows Runtime Type bind. 
END   : The provided identity format is not recognized. (Exception from HRESULT: 0x80132003) 
BEGIN : Immersive bind. 
END   : The system cannot find the file specified. (Exception from HRESULT: 0x80070002) 

这种奇怪行为的原因可能是什么?

请您参考如下方法:

这不是奇怪的行为。 WinRT 硬性阻止了 DLL Hell,这种问题你不能指望商店用户来解决。一个非常严格的要求是所有依赖项都包含在应用程序包中。 Windows 只会在该包中查找 DLL。

这使得使用 .winmd 文件有点用处不大。您只会在大型产品中考虑它,该产品由许多单独打包的独立解决方案构建而成。