Reputation: 1531
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:
Any help with this would be greatly appreciated!
Upvotes: 26
Views: 11156
Reputation: 18013
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.
/// <summary>
/// Split Container Control
/// </summary>
public class SplitContainer : System.Windows.Forms.SplitContainer
#if (NET35)
, ISupportInitialize
#endif
{
#region Constructor
/// <summary>
/// Constructor
/// </summary>
public SplitContainer() : base() { }
#endregion Constructor
#region ISupportInitialize Methods
#if (NET35)
public void BeginInit() { }
public void EndInit() { }
#endif
#endregion ISupportInitialize Methods
}
Upvotes: 2
Reputation: 138
As @tomash mentioned to removes the line of BeginInit() and EndInit() on that specific control is enough.
SplitContainer.BeginInit
.NET Framework Supported in: 4.5, 4
Click here for more info about this method.
Upvotes: 6
Reputation: 1531
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.
Upvotes: 33