MC9000
MC9000

Reputation: 2403

Type 'usercontrol' is not defined (Visual Studio 2015)

I have a custom winforms user control I added to a project in VS2015. When I drag the control to a form and compile, I get the error Type 'xxx' is not defined. I can fix if I remove the namespace from the control name, but any changes to the user control overwrites my changes. Is there a way to prevent this from happening?

Here's the auto-generated control (called "ctrlTestStatus"):

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class ctrlTestStatus
    Inherits System.Windows.Forms.UserControl

    'UserControl overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()>
    Private Sub InitializeComponent()
        Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
        Me.prgLocalDatabase = New System.Windows.Forms.ProgressBar()
        Me.prgRemoteDatabase = New System.Windows.Forms.ProgressBar()
        Me.lblLocalDatabaseStatus = New System.Windows.Forms.Label()
        Me.lblRemoteDatabaseStatus = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.prgAmazon = New System.Windows.Forms.ProgressBar()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.lblAmazonStatus = New System.Windows.Forms.Label()
        Me.prgEbay = New System.Windows.Forms.ProgressBar()
        Me.lblEbayStatus = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.lbStatus = New System.Windows.Forms.ListBox()
        Me.TableLayoutPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'TableLayoutPanel1
        '
        Me.TableLayoutPanel1.BackColor = System.Drawing.SystemColors.Window
        Me.TableLayoutPanel1.ColumnCount = 3
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.30766!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 58.95527!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15.73707!))
        Me.TableLayoutPanel1.Controls.Add(Me.prgLocalDatabase, 1, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.prgRemoteDatabase, 1, 1)
        Me.TableLayoutPanel1.Controls.Add(Me.lblLocalDatabaseStatus, 2, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.lblRemoteDatabaseStatus, 2, 1)
        Me.TableLayoutPanel1.Controls.Add(Me.Label4, 0, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.Label5, 0, 1)
        Me.TableLayoutPanel1.Controls.Add(Me.prgAmazon, 1, 2)
        Me.TableLayoutPanel1.Controls.Add(Me.Label6, 0, 2)
        Me.TableLayoutPanel1.Controls.Add(Me.lblAmazonStatus, 2, 2)
        Me.TableLayoutPanel1.Controls.Add(Me.prgEbay, 1, 3)
        Me.TableLayoutPanel1.Controls.Add(Me.lblEbayStatus, 2, 3)
        Me.TableLayoutPanel1.Controls.Add(Me.Label1, 0, 3)
        Me.TableLayoutPanel1.Location = New System.Drawing.Point(8, 7)
        Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
        Me.TableLayoutPanel1.RowCount = 4
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
        Me.TableLayoutPanel1.Size = New System.Drawing.Size(425, 107)
        Me.TableLayoutPanel1.TabIndex = 8
        '
        'prgLocalDatabase
        '
        Me.prgLocalDatabase.Location = New System.Drawing.Point(110, 3)
        Me.prgLocalDatabase.Name = "prgLocalDatabase"
        Me.prgLocalDatabase.Size = New System.Drawing.Size(244, 20)
        Me.prgLocalDatabase.TabIndex = 0
        '
        'prgRemoteDatabase
        '
        Me.prgRemoteDatabase.Location = New System.Drawing.Point(110, 29)
        Me.prgRemoteDatabase.Name = "prgRemoteDatabase"
        Me.prgRemoteDatabase.Size = New System.Drawing.Size(244, 20)
        Me.prgRemoteDatabase.TabIndex = 1
        '
        'lblLocalDatabaseStatus
        '
        Me.lblLocalDatabaseStatus.Anchor = System.Windows.Forms.AnchorStyles.Left
        Me.lblLocalDatabaseStatus.AutoSize = True
        Me.lblLocalDatabaseStatus.Location = New System.Drawing.Point(360, 6)
        Me.lblLocalDatabaseStatus.MinimumSize = New System.Drawing.Size(40, 13)
        Me.lblLocalDatabaseStatus.Name = "lblLocalDatabaseStatus"
        Me.lblLocalDatabaseStatus.Size = New System.Drawing.Size(40, 13)
        Me.lblLocalDatabaseStatus.TabIndex = 3
        '
        'lblRemoteDatabaseStatus
        '
        Me.lblRemoteDatabaseStatus.Anchor = System.Windows.Forms.AnchorStyles.Left
        Me.lblRemoteDatabaseStatus.AutoSize = True
        Me.lblRemoteDatabaseStatus.Location = New System.Drawing.Point(360, 32)
        Me.lblRemoteDatabaseStatus.MinimumSize = New System.Drawing.Size(40, 13)
        Me.lblRemoteDatabaseStatus.Name = "lblRemoteDatabaseStatus"
        Me.lblRemoteDatabaseStatus.Size = New System.Drawing.Size(40, 13)
        Me.lblRemoteDatabaseStatus.TabIndex = 4
        '
        'Label4
        '
        Me.Label4.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(4, 6)
        Me.Label4.MinimumSize = New System.Drawing.Size(100, 13)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(100, 13)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "Local Database:"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'Label5
        '
        Me.Label5.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(4, 32)
        Me.Label5.MinimumSize = New System.Drawing.Size(100, 13)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(100, 13)
        Me.Label5.TabIndex = 7
        Me.Label5.Text = "Remote Database:"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'prgAmazon
        '
        Me.prgAmazon.Location = New System.Drawing.Point(110, 55)
        Me.prgAmazon.Name = "prgAmazon"
        Me.prgAmazon.Size = New System.Drawing.Size(244, 20)
        Me.prgAmazon.TabIndex = 9
        '
        'Label6
        '
        Me.Label6.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(4, 58)
        Me.Label6.MinimumSize = New System.Drawing.Size(100, 13)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(100, 13)
        Me.Label6.TabIndex = 8
        Me.Label6.Text = "Amazon:"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'lblAmazonStatus
        '
        Me.lblAmazonStatus.Anchor = System.Windows.Forms.AnchorStyles.Left
        Me.lblAmazonStatus.AutoSize = True
        Me.lblAmazonStatus.Location = New System.Drawing.Point(360, 58)
        Me.lblAmazonStatus.MinimumSize = New System.Drawing.Size(40, 13)
        Me.lblAmazonStatus.Name = "lblAmazonStatus"
        Me.lblAmazonStatus.Size = New System.Drawing.Size(40, 13)
        Me.lblAmazonStatus.TabIndex = 5
        '
        'prgEbay
        '
        Me.prgEbay.Location = New System.Drawing.Point(110, 81)
        Me.prgEbay.Name = "prgEbay"
        Me.prgEbay.Size = New System.Drawing.Size(244, 20)
        Me.prgEbay.TabIndex = 11
        '
        'lblEbayStatus
        '
        Me.lblEbayStatus.Anchor = System.Windows.Forms.AnchorStyles.Left
        Me.lblEbayStatus.AutoSize = True
        Me.lblEbayStatus.Location = New System.Drawing.Point(360, 86)
        Me.lblEbayStatus.MinimumSize = New System.Drawing.Size(40, 13)
        Me.lblEbayStatus.Name = "lblEbayStatus"
        Me.lblEbayStatus.Size = New System.Drawing.Size(40, 13)
        Me.lblEbayStatus.TabIndex = 12
        '
        'Label1
        '
        Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(4, 86)
        Me.Label1.MinimumSize = New System.Drawing.Size(100, 13)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(100, 13)
        Me.Label1.TabIndex = 10
        Me.Label1.Text = "Ebay:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'lbStatus
        '
        Me.lbStatus.FormattingEnabled = True
        Me.lbStatus.Location = New System.Drawing.Point(7, 120)
        Me.lbStatus.Name = "lbStatus"
        Me.lbStatus.Size = New System.Drawing.Size(425, 56)
        Me.lbStatus.TabIndex = 9
        '
        'ctrlTestStatus
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Controls.Add(Me.TableLayoutPanel1)
        Me.Controls.Add(Me.lbStatus)
        Me.Name = "ctrlTestStatus"
        Me.Size = New System.Drawing.Size(440, 185)
        Me.TableLayoutPanel1.ResumeLayout(False)
        Me.TableLayoutPanel1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

    Friend WithEvents TableLayoutPanel1 As TableLayoutPanel
    Friend WithEvents prgLocalDatabase As ProgressBar
    Friend WithEvents prgRemoteDatabase As ProgressBar
    Friend WithEvents lblLocalDatabaseStatus As Label
    Friend WithEvents lblRemoteDatabaseStatus As Label
    Friend WithEvents Label4 As Label
    Friend WithEvents Label5 As Label
    Friend WithEvents prgAmazon As ProgressBar
    Friend WithEvents Label6 As Label
    Friend WithEvents lblAmazonStatus As Label
    Friend WithEvents prgEbay As ProgressBar
    Friend WithEvents lblEbayStatus As Label
    Friend WithEvents Label1 As Label
    Friend WithEvents lbStatus As ListBox
End Class

and the designer code for the form I plop the control onto (before I put it in):

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class frmTestStart
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()>
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'frmTestStart
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(468, 206)
        Me.Name = "frmTestStart"
        Me.Text = "Test Connections"
        Me.ResumeLayout(False)

    End Sub

End Class

What the designer generated after I dragged the control and saved:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class frmTestStart
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()>
    Private Sub InitializeComponent()
        Me.CtrlTestStatus1 = New QBI.ctrlTestStatus()
        Me.SuspendLayout()
        '
        'CtrlTestStatus1
        '
        Me.CtrlTestStatus1.Location = New System.Drawing.Point(13, 13)
        Me.CtrlTestStatus1.Name = "CtrlTestStatus1"
        Me.CtrlTestStatus1.Size = New System.Drawing.Size(440, 185)
        Me.CtrlTestStatus1.TabIndex = 0
        '
        'frmTestStart
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(468, 206)
        Me.Controls.Add(Me.CtrlTestStatus1)
        Me.Name = "frmTestStart"
        Me.Text = "Test Connections"
        Me.ResumeLayout(False)

    End Sub

    Friend WithEvents CtrlTestStatus1 As QBI.ctrlTestStatus
End Class

I get the squiggly lines under the QBI.ctrlTestStatus() and it generates the error if I try to compile. I thought it was a namespace bug in the designer, so I immediately wrapped the usercontrol to fix (no joy).The project namespace is QBI (it's not a reserved word as far as I can tell).

Namespace QBI
    Public Class ctrlTestStatus
        Private Sub ctrlTestStatus_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        End Sub
    End Class

End Namespace

Unfortunately, this created more problems and the properties and events for the CtrlTestStatus1 instance are not available (I get squiggly lines).

I found one problem from MS saying to set the compile to Any CPU (which the project build has always been set to this) due to a 64bit / 32bit issue (VS is STILL 32bit!), but no joy either.

Any ideas (settings, things I'm doing wrong) as to how to remedy this?

Upvotes: 1

Views: 701

Answers (1)

Sigenes
Sigenes

Reputation: 495

Old post, but for anyone else having this issue...

I had this happen in a Project where I'd defined a sub-namespace with the same name as my project (root namespace) (in the OP's case, "QBI"). This happens when you have code that looks like this somewhere in your project:

Namespace [Name of your Project/Root Namespace] [...] End Namespace

The result of this is that your project contains both a "QBI" namespace AND a "QBI.QBI" namespace (which you can see for yourself if you look at the Object Browser for your project). This situation causes a resolution conflict in the designer file whereby it looks under the wrong namespace for your custom control.

A few possible ways to fix this:

  1. Where the sub-namespace is declared (as in the example code above), remove the namespace declaration altogether. This will move all the code within the declaration to your root "QBI" namespace. You can do this if having that code in a sub-namespace is unnecessary.
  2. Where the sub-namespace is declared, right-click the Namespace name and rename it to something OTHER than your Root Namespace's name.
  3. If you want to keep the sub-namespace named as such, you can instead rename your root namespace to something unique, from My Project --> Application --> Root namespace.

Option 1 is the simplest option and should immediately resolve the error.

Option 2 is the next simplest, but, for example, if your renamed the sub-namespace to "NewName", all references to "ctrlTestStatus" in your Designer files will be mistakenly renamed to "NewName.ctrlTestStatus", and you'll have to repair them to "QBI.ctrlTestStatus".

Option 3 is the most tedious, because you have to resolve all Designer file references to the Root namespace, using Find and Replace, being careful not to mistakenly replace legitimate references to the sub-QBI namespace.

Upvotes: 1

Related Questions