SplitContainer ISupportInitialize issue: VS2010 Targeting .NET 3.5

Austin picture Austin · May 9, 2011 · Viewed 10.2k times · Source

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:

  1. Create a new C# Windows Forms Application project in Visual Studio 2010 (Make sure to target .NET Framework 4.0)
  2. Add a split container to the basic form.
  3. Run the application (will run just fine)
  4. Change target to .NET Framework 3.5 (properties->Applications->Target Framework:)
  5. Rerun the application (It will crash with the Cast exception).

Any help with this would be greatly appreciated!

Answer

Austin picture Austin · May 17, 2011

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.