We help IT Professionals succeed at work.

User Control - Legal Path Error

Medium Priority
Last Modified: 2012-08-14
Hi there

I have a user control in a project.  The user control appears in the toolbox, but when I go to put it on a form I get the following error:

The path is not of a legal form

If I do it again the user control is put on the form without error, but then I get a compile error that the user control is not defined properly

Does anyone know what this might be?

Any help appreciated!
Watch Question

Is it a control you have made yourself? If it is, can you post the declaration area of it, in particular, the New() sub...?


I am not declaring it I am dragging it from the toolbox and putting it onto my form, vb is doing the rest
What version of Visual Studio are you using?

Anything in the New() sub (if you have one) is executed when you CREATE the control on the form. So it happens in design time as well as runtime.

Make sure the user control class is declared publicly (Public Class usrControl) , and any variables in the declaration area are also declared publicly (where needed). In earlier versions of VS you have to close any design windows of the control before you can place it in any forms.

How have you added it to your form? Did it apear in the toolbox, or did you have to add it in? If you added it in yourself, explain how you did it...


I am running vb 2005 8.0.50727-4200

It added itself to the tool box automatically and it is public.  One thing I have just tried based on what you have said is within the load event of the form I am calling for a particular record of data to be shown within the user control, the user control shows a list of relevant data that on loading the form I need to select corresponding to the item the user has selected before opening the form.  On taking this code out I don't seem to be getting the error, - can I still do this code?


Actually scrub that - I am still getting an error, It is now saying User Control is not defined and compiling the code
Im sure it will be possible to fullfil all your needs... but we need to see the code for the load event, and the new event (if you have one)? I cant advise anything until I can see where its going wrong.



I am not really doing much.  The user control goes into the toolbox automatically, code is:

Public Class Contact_Card

    Public Property Contact_ID() As Long
            Return cbo_Name.SelectedValue
        End Get
        Set(ByVal Value As Long)
            cbo_Name.SelectedValue = Value
        End Set
    End Property

    Private Contact_List As New DataTable

    Public Sub Load_Customer_Contacts(ByVal pCustomerID As Long, Optional ByVal pDefaultContactCardID As Long = 0)


        Load_Data(Contact_List, "select *, first_name + ' ' + last_name as name " & _
                    "from contact_cards cc, contacts c, addresses a " & _
                    "where cc.address_id = a.address_id " & _
                    "and cc.contact_id = c.contact_id " & _
                    "and cc.customer_id = " & pCustomerID)

        cbo_Name.DataSource = Contact_List
        cbo_Name.DisplayMember = Contact_List.Columns("name").ColumnName
        cbo_Name.ValueMember = Contact_List.Columns("contact_card_id").ColumnName

    End Sub

End Class

On selecting user control from toolbox and putting it on form the code I am running on the form is:

 Private Sub Reception_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Call load_Customer(ABC.Customer_ID_Loaded)

    End Sub

    Public Sub load_Customer(ByVal pCustomerID As Long)

        Dim Customer As New DataTable
        DataConnection.Load_Data(Customer, "select * from customers where customer_id = " & pCustomerID)
        If Not IsDBNull(Customer.Rows(0).Item("contact_card_id")) Then
            Me.Contact_Card2.Load_Customer_Contacts(pCustomerID, Val(Customer.Rows(0).Item("contact_card_id")))
        End If

    End Sub
Doesn't the debugger's error window point you to the erroring code? It may even be in the Form_Generated code section?

I can't see anything that suggests its coded wrong... It looks ok to me.

Where do you reference the control? "Contact_Card"?


Contact card is in my project, it auto puts it in the toolbox and I drag from the tool box and put on my form, so I don't reference it per se.

I either get an error in the form designer or in an error list and the errors tends to cycle between all 3, i.e. fix on get the next and so on:

The variable 'Contact_Card1' is either undeclared or was never assigned.
Hide    Edit

at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)


 One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.

The path is not of a legal form.

at System.IO.Path.NormalizePathFast(String path, Boolean fullCheck)
at System.IO.Path.GetFullPathInternal(String path)
at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AddProjectDependencies(Project project)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.Search(String fullName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, String description)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchProjectEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.GetType(ITypeResolutionService trs, String name, Dictionary`2 names)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.FillStatementTable(IDesignerSerializationManager manager, IDictionary table, Dictionary`2 names, CodeStatementCollection statements, String className)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)


In the error list on compile I get:

ABC.Contact_Card is not defined

(if I delete ABC. is compiles and works, but ABC. gets put back in again)

Thanks for your help
I dont know why your referencing it as ABC.Contact_Card...? It should just be Contact_Card.

In your last post you refered to it as Contact_Card and Contact_Card1, i dont know if that was a typo or not, but if it wasn't its worth changing the name of the control (on your form), to something different to anything that resembles the filename/controlname.

Can you access the properties to it? If you type its name + . (Contact_Card.) do you get a list of properties?

Its not an obvious one unfortunately, sorry i am not able to offer a quicker fix...


> I dont know why your referencing it as ABC.Contact_Card...? It should just be Contact_Card.

thats the problem ABC is the namespace/name of project.  I am not putting ABC in VB.NET is putting it in.  I keep deleting it and VB keeps putting it back in.  I have no idea how to stop it doing this.

2nd point - yes it was a typo

yes I can get properties of it, even the one I have defined myself appears.

This deals with .net 2003 but may relate to 2005 also:

"In Microsoft Visual Studio .NET 2003, you may be not be able to add a user control from the Toolbox to a Microsoft Windows Form. "



Thanks for that one http://support.microsoft.com/kb/825007, but VS2005 doesn't have a ProjectAssemblies folder, but it is the same symptoms you are right
Try this:

1.  Place a panel on you form.
2.  Put the following in your form load event.

Dim tempObject As New YourUserControl ' Create an object of the user control.
panel1.Controls.Clear()                             ' Clear anything that the panel is displaying.
panel1.Controls.Add(tempObject)             ' Add the control to the panel which will automatically display it

3.  Run and see if it puts the user control in the panel on the form.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thanks! Now that does seem to work without an error!  Bit of a pain to have to define it in code each time I want to use a user control  (was planning to reuse several controls on most forms) :OS

Any idea why this is?

I really can't answer that.  I have a project with several user controls and I tried to simulate your problem.  I found that if I had a user control with code in it I got an error when I tried to place it on a form but if the user control had no code it moved from the toolbox just fine.  Maybe in the future you should create your user control and move it to the form before you do any coding and see if that helps.  With my project, I have 8 buttons (menu) that I can call 8 user controls to only one form.


ok, I will try that - thank you very much for your help - you have made things much better for me!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.