views:

10

answers:

1

I have created a custom control using VB.NET in Visual Studio 2008 that gives extensive mapping and tracking functionality to a search and rescue app. The problem I am having is that in a number of places I need to define the path to the main applications executable in order to find a number of directories the control needs to function properly. Everything works fine when I am using it in VS but when I try to embed the control in a form in a separate solution I get the following error:

Failed to create component 'MainControl'. The error message follows: 'System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Microsoft\Visual Studio 9.0\Common\IDE\GIS\Data\Default...

This seems to indicate that it is looking for the \GIS\Data\Default directory in the Visual Studio program path but I have used Application.StartupPath to define this location throughout the control.

This error only occurs when attempting to embed the control in a form outside of the controls solution. The solution I have created to develop this control has two projects (one for the control and one for a test form to do the debuging)

Can anyone provide me with some guidance on this?

A: 

This will happen when your control executes code while it is being used in the designer. It does, stuff like the constructor, Load event, Paint event, etcetera will run when you drop the control on a form in Visual Studio.

You need to use the DesignMode property to prevent this code from running, and crashing, when the current working directory is wrong. It will be wrong in the designer, the working directory is Visual Studio's, not the app's in which it will eventually be used. Or use absolute paths, not relative paths.

If that doesn't help, how to debug design time problems is explained here.

Hans Passant
Thanks Hans that did the trick. It's kinda funny, I've been developing in VB.NET for about three years now and this is the first time I have come across this issue. Anyway, your solution was the right one.
Gerry