How can I solve 'Could not load file or assembly' error in XAML Designer for C# WPF app using C++ managed dll wrapper?

huangapple go评论57阅读模式
英文:

How can I solve 'Could not load file or assembly' error in XAML Designer for C# WPF app using C++ managed dll wrapper?

问题

我有一个使用.NET Framework 4编写的C# WPF应用程序,它使用来自引用的托管dll包装器(包装了一个不受托管的C++ dll)的函数。
所以:

HMI_Main <— HMI_ClientWrap <— HMI_Client <— HMI_IPC

其中:

HMI_Main: C#可执行文件,

HMI_ClientWrapper: C++托管dll

HMI_Client: C++不受托管的dll

HMI_IPC: C++不受托管的dll

这在发布配置下都正常工作,我的XAML设计器显示我的用户控件。
然而,在调试配置下,XAML设计器中没有显示任何用户控件,只显示错误“无法加载文件或程序集‘HMI_ClientWrapd.dll’或其依赖项之一。找不到指定的模块。”
代码后端仍然正常工作,并且可以访问DLL中导出的函数。

我想问题可能出在我的用户代码中,但很难找到问题,因为唯一抱怨的是设计器。
depends.exe 也没有显示任何问题,Visual Studio 的其他部分也没有抱怨,dll已解析等等。

有没有办法排查设计器的问题?

我尝试查找Visual Studio的日志文件,但似乎没有什么存在。
Dependency Walker 也没有报告任何问题。

英文:

I have a .NET Framework 4 C# WPF application that uses functions from a referenced managed dll wrapper (a wrapper that wraps an unmanaged C++ dll).
So:

HMI_Main &lt;— HMI_ClientWrap &lt;— HMI_Client &lt;— HMI_IPC

Where:

HMI_Main: C# executable,

HMI_ClientWrapper: C++ managed dll

HMI_Client : C++ unmanaged dll

HMI_IPC: C++ unmanaged dll

This all works fine in Release configuration and my XAML designer displays my usercontrols.
In Debug configuration, however, no usercontrols are displayed in XAML Designer, only the error Could not load file or assembly ‘HMI_ClientWrapd.dll’ or one of its dependencies. The specified module could not be found.
The code behind still works fine and can access exported functions from the DLL.

I suppose the problem is within my usercode, but it is very difficult to find the problem as the only thing complaining is the Designer.
depends.exe also shows no problems, and other parts of Visual Studio does not complain, dlls are resolved etc.

Is there any way to troubleshoot the designer?

I've tried finding log files for Visual Studio but it doesn't really seem to exist anything.
Dependency walker doesn't report any problem.

答案1

得分: 2

事实证明,这些dll文件位于不同的目录中,而依赖项查看器已经过时,无法正确显示。

我改为使用这里的分支依赖项查看器:https://github.com/lhak/Dependencies,它立即识别出了问题。

之所以发布版本正常工作是因为我将包含dll文件的文件夹添加到了Windows路径环境变量中。

英文:

Turns out the dlls were located in a different directory and dependency walker was too outdated to display it correctly.

I instead used the forked dependency walker from here: https://github.com/lhak/Dependencies which immediately identified the issue.

The reason release was working was because I had the folder where the dlls were built to in my Windows Path environment variable

huangapple
  • 本文由 发表于 2023年6月1日 15:22:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379544.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定