2
votes

Hello i am getting a weird error in my application.

there are times when i open my form in design view (form not running), i do not get any error, and sometimes i get an error value does not fall within expected range.

when i close my solution and open it again, the form works fine,then start running the application, and stop it and open the form (same stuff, it may work or sometime it may not work).

also this does not always happen to the same form, it happens to random different form, sometimes i can get it in form 1, sometimes in form 2,

Here is a printscreen of that error

3
Your default constructor probably does not initialize values to sane defaults. - leppie
Is this helpful? social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/…. A Google search on that error message returns a ton of similar questions. - Jim Mischel
Often clicking "Show Call Stack" helps to identify where these errors are hidden. Is it possible that you have some constructor code that is setting an invalid value, or is perhaps reading data from a database connection not available consistently at design time? - JoshL
This is a pain, I've suffered too. Check all code in constructor, including the design.cs file. Check InitializeComponent method too. Get rid of warnings and errors. Also check the form's Load event handler if you've implemented it. Think of it this way: the designer compiles your constructor and form's load code and if there is a problem you get a this issue. - bytefire
@bytefire thanks i will check it out. - avi

3 Answers

3
votes
  1. Close Visual Studio and deleted all *.user and other temporary or user-specific files.
  2. Open Visual Studio and rebuild your project.
  3. Open the form and the problem should be solved.

If your using SVN, just use the "cleanup" command to delete all unversioned or ignored files.

0
votes

Seeing this screen can be maddening because it is the result of an exception being thrown at design time (i.e. if it were being throw at runtime then handling the catch-all AppDomain.CurrentDomain.UnhandledException might offer a clue).

But there is a way to get visibility on exceptions thrown while the Designer is trying to load by using Visual Studio to debug Visual Studio:

  • Open TWO instances of Visual Studio.
  • In INSTANCE ONE on the Main Menu Select Debug\Attach to Process
  • Attach to INSTANCE TWO of Visual Studio by selecting devenv.exe as the process.
  • Now just open your project in INSTANCE TWO.

Two main benefits:

  1. The Output window of INSTANCE ONE will provide verbose reporting as your solution loads.
  2. A Design-Time exception that occurs when you try to open the Designer in your project in INSTANCE TWO will cause an exception break in INSTANCE ONE. Now sometimes the stack trace helps and sometimes it doesn't. But I've usually found it more helpful to have some visibility rather than none at all.
0
votes

Close VS then delete .suo file (.vs\solution_name\vXX.suo). This will close all tabs but you can reopen them.