SplitContainer ISupportInitialize 问题:VS2010 针对 .NET 3.5
在 VS2010 中,我有一个针对 .NET Framework 4.0 的项目,然后必须恢复到目标 v.3.5。一旦发生这种情况,我拥有的 SplitContainer 对象将不会显示,并且实际上会抛出错误:“无法将类型为‘System.Windows.Forms.SplitContainer’的对象转换为类型为‘System.ComponentModel.ISupportInitialize’。”
现在,我做了一些挖掘,发现 3.5 实际上在 SplitContainer 上没有 ISupportInitialize,而在 .NET 4.0 中却有。我想我的问题是,如果我的目标是 3.5 但仍然遇到此问题,我该如何解决此问题?
重现问题的步骤:
- 在 Visual Studio 2010 中创建一个新的 C# Windows 窗体应用程序项目(确保面向 .NET Framework 4.0)
- 将拆分容器添加到基本窗体。
- 运行应用程序(将运行得很好)
- 将目标更改为 .NET Framework 3.5(属性->应用程序->目标框架:)
- 重新运行应用程序(它将因 Cast 异常而崩溃)。
任何对此的帮助将不胜感激!
In VS2010 I had a project targeting .NET Framework 4.0 and then had to revert to target v. 3.5. Once this happened, the SplitContainer object that I had will not display and will actually throw an error: "Unable to cast object of type 'System.Windows.Forms.SplitContainer' to type 'System.ComponentModel.ISupportInitialize'."
Now, I did some digging and found out that 3.5 does not, in fact, have ISupportInitialize on the SplitContainer and it does in .NET 4.0. I guess my question is, if I am targeting 3.5 and still getting this issue, how do i correct this?
Steps to reproduce problem:
- Create a new C# Windows Forms Application project in Visual Studio 2010 (Make sure to target .NET Framework 4.0)
- Add a split container to the basic form.
- Run the application (will run just fine)
- Change target to .NET Framework 3.5 (properties->Applications->Target Framework:)
- Rerun the application (It will crash with the Cast exception).
Any help with this would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了这个问题的解决方案,它非常特别...如果您将表单回退到 3.5,则必须对程序中的每个表单进行一些小更改,以便编译器重新生成所有代码对于那种形式。我遇到问题的原因是因为我没有进行任何更改,并且正在尝试运行尚未重新生成的代码。
I found the solution to this problem and it was quite special... IF you backrev your forms to 3.5, you have to do a small change on EACH AND EVERY form you have in your program so that the compiler will regenerate all of the code for that form. The reason I was having an issue was because I had made no change and was trying to run the code, which had not been regenerated.
正如 @tomash 提到的,删除该特定控件上的 BeginInit() 和 EndInit() 行就足够了。
单击 此处了解有关此方法的更多信息。
As @tomash mentioned to removes the line of BeginInit() and EndInit() on that specific control is enough.
Click here for more info about this method.
这是一篇旧文章,但我不喜欢每次都编辑设计器文件,这样会留下太多的错误空间。
我只是对控件进行了子类化,并使用预处理器指令实现了 .net 3.5 构建的接口,如下所示。
只是添加我的方法,因为这篇文章是在 2017 年寻找解决方案时出现的。
This is an old post but I did not like having to edit the designer files every time, leaves too much room for mistakes.
I just subclassed the control and implemented the interface for .net 3.5 builds as below using preprocessor directives.
Just adding my method as this post came up in 2017 when looking for a solution.