VS2010中WinForms视觉继承问题
快速了解一下相关项目的背景:它是 C# .Net 4、带有智能客户端工厂的 WinForms,不幸的是有很多视觉继承。
以下是我正在处理的团队遇到的问题的简要概述,该问题似乎相当间歇性:
有人将打开其中一个客户端模块项目以开始处理其中一个视图,双击该视图以打开设计器和 Visual Studio 会给他们一个设计时错误,例如:
事情已经没有回头路了;如果您从此处重建而不执行以下解决方法,则错误仍然存在。我们发现的唯一解决方法是清理客户端解决方案,关闭 Visual Studio(您必须这样做),重新打开 Visual Studio 并重建解决方案。下次您尝试打开视图时它将起作用。但错误会再次出现 - 似乎是在 X 次重建之后(可能仅当您在构建解决方案时在设计器中打开视图时?)
没有人花时间想要真正深入研究这个问题,但目前没有人有时间!所以我想知道(有点不太可能)是否有人知道会发生什么?或者,一旦我们有时间研究这个问题,我们可能会知道从哪里开始挖掘?
Quick bit of background to the project in question: it's C# .Net 4, WinForms with smart client factory and unfortunately a lot of visual inheritance.
Here's a brief outline of the problem the team I'm working on are experiencing which seems to be fairly intermittent:
Someone will open up one of the client module projects to begin work on one of the views, double click on the view to open up the designer and Visual Studio will give them a design time error such as:
There's no way back from this; if you rebuild from here without doing the following work around then the error will still persist. The only work around we've found is to clean the client solution, close Visual Studio (you have to do that), reopen Visual Studio and rebuild the solution. Next time you try to open the view it will work. But the error will come back again - it seems to be after X amount of rebuilds (possibly only while the view is open in the designer whilst you're building the solution?)
No one has taken the time out to really dig into this problem and at the moment no one has the time! So I was wondering (bit of a long shot) if anyone might have an idea about what could be going on? Or perhaps an inkling of where to start digging once we get a bit of time to look into this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用视觉继承,这些问题就是生活中的一个事实,并且它们不太可能消失。
我在当前的项目中广泛使用了 UserControl 继承。我以前经常遇到你描述的问题。随着时间的推移,我已经将设计细化到现在只偶尔发生的地步,而且我很少需要再进行干净-重新启动-重建的舞蹈了。
您的情况可能会有所不同,但我认为我为减少此问题所做的主要事情是摆脱设计时程序集间数据绑定。
一个示例是,将 BindingSource 放到窗体上并将其数据源设置为另一个程序集中的类型。
(嗯,它总是来自另一个程序集,因为我从来没有在与我的 UI 相同的程序集中定义类型。所以据我所知,程序集间的事情甚至可能不是一个因素。)
无论如何,我最终摆脱了大部分或全部这些设计时绑定并在运行时设置我的所有绑定。问题已经解决了 99%。它仍然偶尔发生,但我懒得去尝试解决它。
无论你做什么,都不要从通用基类继承表单/控件。 100% 的情况下它都会被破坏。如果您需要这样做,可以通过快速搜索找到解决方法。
微软几乎肯定永远不会解决这些问题,所以要习惯它们。
If you use visual inheritance, these problems are a fact of life and they're not likely to ever go away.
I make extensive use of UserControl inheritance in my current project. I used to get the problem you're describing very frequently. Over time I've refined the design down to the point where it only happens occasionally now, and I rarely have to do the clean-restart-rebuild dance anymore.
You mileage will probably vary, but I think the main thing I did to reduce this problem was to get rid of design-time inter-assembly data bindings.
An example of this is when you drop BindingSource on your form and set its datasource to a type from another assembly.
(Well, it's always from another assembly because I never define types in the same assembly as my UI. So for all I know, the inter-assembly thing may not even be a factor.)
Anyway I ended up getting rid of most or all of these design-time bindings and setting up all my bindings at runtime. The problem has 99% gone away. It still happens occasionally but I don't bother to try to troubleshoot it.
And whatever you do, don't inherit a form/control from a generic base class. That breaks it 100% of the time. If you need to do this, there's a workaround which you can find with quick search.
Microsoft will almost certainly never fix these problems, so get used to them.