0

I am using Visual Studio 2017 and I am trying to fix an error I got:

The designer loader did not provide a root component but has not indicated why.

And then when I close and re-open I get this error:

Exception of type 'System.ComponentModel.Design.ExceptionCollection' was thrown.

I am trying to follow this answer: System.ComponentModel.Design.ExceptionCollection

  1. I cant find:

In one instance, goto Debug->Exceptions and enable all the 'Thrown' options to stop at first chance exceptions

So I went to Debug>Windows>Exception Settings. But I was not certain what to check since there is no 'Thrown' that seems to make sense. Maybe check everything?

  1. I can't attach to the process it is missing when I tried to do this:

    In the same instance, select Debug->Attach to Process, select devenv.exe. enter image description here

This is what I got when I debugged it with Jimi's suggestions: 1: https://i.stack.imgur.com/VLyJm.png

The form works fine at run time, it only has an issue at design time.

Jeff
  • 155
  • 1
  • 10
  • [Walkthrough: Debug Custom Windows Forms Controls at Design Time](https://learn.microsoft.com/en-us/dotnet/framework/winforms/controls/walkthrough-debugging-custom-windows-forms-controls-at-design-time) – Jimi Aug 22 '20 at 21:15
  • Before you start another debug session for nothing, do a Clean-Solution, Rebuild-Solution (not the Project, the Solution), close VS, go to your Solution's folder and delete the `\[Solution]\[Project]\Obj` folder (just the `Obj` folder :). Depending on the VS version, also the (Hidden) `.vs` folder you can find one level down the main Solution folder. If a Control, for some reason, is possibly using run-time values at design-time (thus, non initialized\null values\objects), see: [Error when opening User Control / Form with Designer](https://stackoverflow.com/a/3621903/7444103). – Jimi Aug 22 '20 at 21:38
  • This is what I got when I debugged it with Jimi's suggestions: [1]: https://i.stack.imgur.com/VLyJm.png – Jeff Aug 24 '20 at 23:13
  • Review the code in your control and use the [DesignMode property of the Component class](https://stackoverflow.com/questions/1166226/detecting-design-mode-from-a-controls-constructor) to wrap your code that should run at runtime. – Xingyu Zhao Aug 25 '20 at 02:26
  • How can I find the line number of the error? I tried adding breakpoints but it does not hit them at design time. – Jeff Aug 25 '20 at 17:56
  • The form works fine at run time, it only has an issue at design time. – Jeff Aug 25 '20 at 18:02
  • Can you help with this. 6. I am not sure where to put this, I am getting an error.. The designer cannot process the code at line 45... . `Dim designMode As Boolean = (System.ComponentModel.LicenseManager.UsageMode = System.ComponentModel.LicenseUsageMode.Designtime)` – Jeff Aug 26 '20 at 23:27

1 Answers1

1

Here is what I came up with for a solution.

  1. I checked my code into Git to save the design file (you can also manually save in notepad or save the code file for a backup).
  2. I opened the code file and left it open to get past this error: Exception of type 'System.ComponentModel.Design.ExceptionCollection' was thrown.
  3. I double clicked the form (or you can right click on the code to view designer).
  4. I got a new error that I could ignore to skip: The designer loader did not provide a root component but has not indicated why.
  5. I had to then move something on the form so that the form would re-generate designer code. Otherwise the error would keep coming up.
  6. EDIT: I am not sure where to put this, but it should work. I am still trying to fix this, but here is what I have so far. I found a line of code causing issues. So I am going to use this to only run at runtime. Dim designMode As Boolean = (System.ComponentModel.LicenseManager.UsageMode = System.ComponentModel.LicenseUsageMode.Designtime)

BAM! Fixed :) Thanks for all your help guys!

Jeff
  • 155
  • 1
  • 10