问题:我有一个 WinForms 控件(“MyControl”)依赖于 myCli.dll,这是一个用 C++ CLI 编写的 dll。该组件是第三方的(由另一个团队编写)。 myCli.dll 依赖于另一方编写的 myLibrary.dll。该控件位于 myAssembly.dll 中,这是一个 C# 控件和资源库。
当 myCli.dll 不依赖于 myLibrary.dll 时,我让这个控件工作得很好。我可以将它添加到表单、构建它等等。但是新版本的 myCli.dll 出来了,我重新链接了它。突然,IDE 表现不佳。关键问题似乎是 IDE 无法解析 myCli.dll 对 myLibrary.dll 的依赖性。
当我尝试将控件从工具箱拖动到设计图面时,出现错误:
"Failed to create component 'MyControl'.
错误信息如下:
'System.IO.FileNotFoundException: Could not load file or assembly 'myCli.dll, Version 0.0.0.0, Culture=neutral, PublicKeyToken=2fb8da784abc560a' or one of its dependencies.
The system cannot find the file specified"
我的信念是,如果我能弄清楚将 myLibrary.dll 放在哪里,我就会解决引用问题。我不确定。有人知道我应该怎么做才能解决这个问题吗?
最佳答案
在我的例子中,我在 Initialize 和 Form_Load 上的代码包含对另一个项目的调用,具体取决于 DLL 引用。通过用
排除此代码if (!DesignMode)
{
//add your initializing code (for runtime!) here
}
我能够在设计时添加控件。
HTH
关于c# - 由于 Unresolved 依赖关系,无法使用 Winforms 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1089770/