c# - 由于 Unresolved 依赖关系,无法使用 Winforms 控件

标签 c# .net winforms user-controls controls

问题:我有一个 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/

相关文章:

C# ComboBox 不显示数据源

c# - 从显示下拉列表不是默认值的下拉列表中捕获值

c# - 如何覆盖数据网格列标题的自动创建?

.net - 注册托管 COM 组件时是否需要 'Implemented Categories' key ?

c# - 返回不同的 HTTP 状态码进行测试

c# - 从 BackgroundWorker 线程访问 UI 控件

c# - 如何在 C# 中根据索引拆分列表?

c# - 了解 AttachThreadInput - 分离失去焦点

c# - XPathNavigator 是否需要 MoveToParent()/MoveToFirstChild() 对?

c# - 使用 DotNetOpenAuth 将推文发布到 Twitter 帐户