User Control - Legal Path Error

Posted on 2006-11-02
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!
Question by:DavidGreenfield
  • 9
  • 5
  • 3

Expert Comment

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

Author Comment

ID: 17857602
I am not declaring it I am dragging it from the toolbox and putting it onto my form, vb is doing the rest

Expert Comment

ID: 17857610
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...

Author Comment

ID: 17857698
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?

Author Comment

ID: 17857720
Actually scrub that - I am still getting an error, It is now saying User Control is not defined and compiling the code

Expert Comment

ID: 17857768
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.


Author Comment

ID: 17857883
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

Expert Comment

ID: 17857927
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"?
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!


Author Comment

ID: 17858043
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

Expert Comment

ID: 17859489
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...

Author Comment

ID: 17859653
> 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.


Expert Comment

ID: 17859964
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. "

Author Comment

ID: 17860218
Thanks for that one, but VS2005 doesn't have a ProjectAssemblies folder, but it is the same symptoms you are right

Accepted Solution

maralans earned 500 total points
ID: 17860841
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.

Author Comment

ID: 17861297
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?

Expert Comment

ID: 17861532
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.

Author Comment

ID: 17862094
ok, I will try that - thank you very much for your help - you have made things much better for me!

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now