I've got a control that crashes on the form designer when I build the application, and am trying to figure out how to debug the problem.
I thought all I needed to do to be able to get in with a debugger was to start a second copy of VS and use Debug-Attach to process and attach to the copy of visual studio that the solution with my troublesome control is in. I did that but nothing is happening when the control crashes so I know I'm doing something wrong...
The crash occurs in the designer and returns the messagebox:
---------------------------
Microsoft Visual Studio
---------------------------
The control NameSpace.MyControl has thrown an unhandled exception in the designer and has been disabled.
Exception:
Could not load file or assembly 'OtherProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Stack trace:
at NameSpace.MyControl.OnPaint(PaintEventArgs e)
---------------------------
OK
---------------------------
OtherProject is part of the solution and is referenced by the project with both the form and the custom control in it.
When I dismiss the messagebox the control shows a stacktrace where the control is on my form, but since it doesn't include line numbers I don't know where the problem is coming from.
The search path for assemblies is different when they get loaded at design time, it will be probing path for Visual Studio. Which is configured by the devenv.exe.config file in Common7\IDE. Only the Public Assemblies and Private Assemblies folders are included. The build directory of your project is not considered.
Modifying this .config file or copying your assembly into one of these folders is not exactly practical. By far the best thing to do is to just not call the code that requires this assembly at design time. Use the DesignMode property:
protected override void OnPaint(PaintEventArgs e) {
if (!this.DesignMode) {
// Runtime painting code here
//...
}
base.OnPaint(e);
}