.Net Designer 程序集,C++\C# 错误

发布于 2024-08-28 00:57:55 字数 681 浏览 3 评论 0原文

我正在开发一个设计人员较多的应用程序(使用 Visual C++ 2.0,但 C# 解决方案应该仍然相关)。我的设置是这样的:

我有一个名为“Host”的用户控件 我正在尝试名为“Child”的 UserControl

Child 包含一个类的属性,该类的类型完全在不同的 dll 中定义,名为“mytools.dll”

Child 在设计器中工作得很好。但是,当我从设计器中将“child”拖到“host”上时,出现以下错误:

Failed to create component 'Child'.  The error message follows:  'System.io.filenotfoundexception: could not load file or assembly MyTools, Version XXXXXX, Culture=neutral
.....
{unhelpful callstack}

如果我注释掉“child”中指向 mytools.dll 中的类的属性,则所有内容都会设计得非常漂亮。我的属性标记为“Browsable(false)”和“DesignerSerialized(hidden)”,但它没有帮助。

有没有办法让我明确地说“不要加载这个 dll,你在设计时不需要它” “,或者我可以通过某种方式强制以编程方式从设计器加载 dll?

谢谢!

I'm working on an designer-heavy application (using Visual C++ 2.0, but a C# solution should still be relevant). My setup is this:

I have a UserControl named "Host"
I'm attempting a UserControl named "Child"

Child contains a property to a class whose type is defined in a different dll entirely, named "mytools.dll"

Child works just fine in the designer. However, when I go to drag "child" onto "host" from the designer, I get the following error:

Failed to create component 'Child'.  The error message follows:  'System.io.filenotfoundexception: could not load file or assembly MyTools, Version XXXXXX, Culture=neutral
.....
{unhelpful callstack}

If I comment out the property in "child" that points to the class in mytools.dll, everything designs just peachy. I have the property marked with "Browsable(false), and DesignerSerializable(hidden), and it does not help.

Is there a way for me to explicitly say "Don't load this dll, you won't need it in design time", or some way for me to force a dll to load from the designer programmatically?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心不设防 2024-09-04 00:57:55

如果该属性被标记为“公共”,则用户控件将强制设计者加载外部程序集。

您必须重新设计您的控件以返回 Object 而不是错误类型,并且如果必须将其保持为公共,则必须进行类型转换,否则,受保护应该没问题。

If the property is marked 'public' then the UserControl will force the designer to load the external assembly.

You must rework your control to return Object instead of the bad type, and do typecasting if you must keep it public, otherwise, protected should be fine.

陪我终i 2024-09-04 00:57:55

不,这里存在先有鸡还是先有蛋的问题。为了找到您应用的属性,设计者必须使用反射来加载类型。加载类型还需要加载其成员使用的任何类型。这将导致 CLR 寻找您的 mytools.dll 程序集。

在设计时有效的探测路径是 Visual Studio 的探测路径,而不是您的应用程序的探测路径。这条路到底是什么样子对我来说是模糊的。工具箱也发挥着作用。它在私有目录中创建包含控件的程序集的副本。查找的位置是 c:\users\yourname\appdata\local\microsoft\visualstudio\9.0\projectassemblies。这经常会出错,并且杂散副本会留在该目录中。当我注意到工具箱初始化开始变慢时,我必须不时地手动清理它。

好吧,您可以检查一下 mytools.dll 的副本是否也存在,并且不是旧版本。将其交给 GAC 是避免麻烦的一种方法。

No, there's a chicken-and-egg problem here. In order to find the attributes you applied, the designer has to use Reflection to load the Type. Loading the type requires any types used by its members to be loaded as well. Which will cause the CLR to go hunting for your mytools.dll assembly.

The probing path in effect at design time is the one for Visual Studio, not your app's. What exactly that path looks like is murky to me. The toolbox plays a role as well. It makes a copy of the assembly that contains the control in a private directory. The place to look is c:\users\yourname\appdata\local\microsoft\visualstudio\9.0\projectassemblies. This often goes wrong and stray copies are left behind in that directory. I have to clean it out by hand from time to time when I notice that toolbox initialization starts to get slow.

Well, something you can check to see if a copy of mytools.dll is present there as well and isn't an old version. Putting it the GAC is one way to stay out of trouble.

软的没边 2024-09-04 00:57:55

UserControl 有一个 DesignMode 属性,但我不确定 .NET 是否想要预先解析该类型(即,如果 DesignMode == true,则返回 null)。

或者,如果您是唯一的开发人员,您可以处理 AppDomain.CurrentDomain.AssemblyResolve 事件并自行加载虚拟程序集。

UserControl has a DesignMode property, but I'm not sure if .NET wants to resolve the type beforehand (ie. return null if DesignMode == true).

Alternatively if you're the only developer you could handle the AppDomain.CurrentDomain.AssemblyResolve event and load a dummy assembly yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文