Cry about...
.NET / VB.Net Troubleshooting
Type '<type-name>' is not defined (VB.Net)
(or which namespace do I need for type <type-name>?)
Symptom:
When compiling a VB.Net application the compiler generates the following error:
error BC30002: Type 'TTTT' is not defined.'
Earlier versions of visual studio may not include the error code
("error BC30002:
").
where 'TTTT
' is the name of a class.
If you are using C# then the error is slightly different:
error CS0246: The type or namespace name 'TTTT' could not be found (are you missing a using directive or an assembly reference?)
in this case please refer to the C# version of this article "The type or namespace name could not be found".
Cause:
The compiler does not recognise the class name 'TTTT
'.
This is either because the class name is miss-spelt or because the compiler
could not find a corresponding definition.
Possible remedies:
- A common cause is a simple misspelling where the class name is used.
For example:
dim connection as OdbcConection
Here the class name should have been '
OdbcConnection
', so the solution is to correct the spelling. - If the name refers to a component defined in the same project and then see my notes for "Type <component-name> is not defined".
- If the name is correct then the next most likely cause is that the
required namespace has not been included.
For example:
dim connection as OdbcConnection
.
.
[Error] Type 'OdbcConnection' is not defined.In this example 'OdbcConnection' is defined in the namespace 'System.Data.Odbc' (although this differs been the .Net framework 1.0 and later versions). Try importing the necessary namespace, so in this case:
Imports System.Data.Odbc
Note that this "Imports" statement must be included at the very top of the file (i.e. before any code).
The following table (which is not exhaustive) lists .NET class names together with the namespace that defines them:
Name Namespace AppSettingsReader System.Configuration ArrayList System.Collections ASCIIEncoding System.Text AspNetCompatibilityRequirements
as in <AspNetCompatibilityRequirements ...System.ServiceModel.Activation Assembly System.Reflection AttributeCollection System.Web.UI BasicHttpBinding System.ServiceModel BasicHttpSecurity BinaryFormatter System.Runtime .Serialization .Formatters .Binary Bindable
as in <Bindable ...System.ComponentModel Bitmap System.Drawing Browsable
as in <Browsable ...System.ComponentModel Brush System.Drawing Button System.Web.UI.WebControls CancelEventArgs System.ComponentModel CheckBoxList System.Web.UI.WebControls ClientCredentials System.ServiceModel.Description Color System.Drawing ColorMatrix System.Drawing.Imaging ComboBox System.Windows.Forms CompositeControl System.Web.UI.WebControls CompositeControlDesigner System.Web.UI.Design.WebControls ConcurrentBag System.Collections.Concurrent Control System.Web.UI ControlCollection System.Web.UI CultureInfo System.Globalization DataRow System.Data DataTable System.Data DateTimeFormatInfo System.Globalization DbContext System.Data.Entity DbSet
as in DbSet(Of ...System.Data.Entity DebuggerStepThrough
as in <DebuggerStepThrough>System.Diagnostics DefaultProperty
as in <DefaultProperty ...System.ComponentModel DefaultValue
as in <DefaultValue ...System.ComponentModel Description
as in <Description ...System.ComponentModel DescriptionAttribute System.ComponentModel DESCryptoServiceProvider System.Security.Cryptography DialogResult System.Windows.Forms Dictionary
as in Dictionary(Of ...System.Collections.Generic DictionaryEntry System.Collections DirectoryInfo System.IO DllImport System.Runtime.InteropServices EventArgs System EventLog System.Diagnostics EventLogInstaller System.Configuration.Install
Note: Project needs a reference to system.configuration.install.dllException System Expression System.Linq.Expressions
From .NET 3.5Extension
as in <Extension()>System.Runtime.CompilerServices
From .NET 3.5FieldInfo System.Reflection FileOutputStream Java.IO
Note: Project needs a reference to vjslib and server requires the Visual J# runtime.FileSecurity System.Security.AccessControl FileStream System.IO FolderNameEditor System.Windows.Forms.Design
Note: Project needs a reference to System.Design, which is included in the full .NET framework but not in the cut down .NET Framework Client Profile.Font System.Drawing FtpWebRequest System.Net FtpWebResponse System.Net Graphics System.Drawing GZipStream System.IO.Compression
From .NET 2.0HMACSHA1 System.Security.Cryptography HtmlHead System.Web.UI.HtmlControls HtmlMeta System.Web.UI.HtmlControls HtmlTextWriter System.Web.UI HttpBrowserCapabilities System.Web HttpRequest System.Web HttpRequestMessageProperty System.ServiceModel.Channels HttpRuntime System.Web HttpSessionState System.Web.SessionState HttpStatusCode System.Net HttpsTransportBindingElement System.ServiceModel.Channels HttpWebRequest System.Net HttpWebResponse System.Net HybridDictionary System.Collections.Specialized IClientMessageInspector System.ServiceModel.Dispatcher ICloneable System ICryptoTransform System.Security.Cryptography IEndpointBehavior System.ServiceModel.Description IEnumerator System.Collections IHTMLDocument2 MSHTML
Note: Project needs a reference to the Microsoft HTML Object Library.ImageAttributes System.Drawing.Imaging ImageClickEventArgs System.Web.UI Imaging System.Drawing IPAddress System.Net IPEndPoint System.Net IPGlobalProperties System.Net.NetworkInformation IPHostEntry System.Net ISerializable System.Runtime.Serialization IsolatedStorageFile System.IO.IsolatedStorage Label System.Web.UI.WebControls List
as in List(Of ...)System.Collections.Generic ListBox System.Web.UI.WebControls ListDictionary System.Collections.Specialized ListItemCollection System.Web.UI.WebControls LiteralControl System.Web.UI MailAddress System.Net.Mail MailMessage In .NET 1.1: System.Web.Mail
From .NET 2.0: System.Net.MailManagementScope System.Management
Note: Project needs a reference to System.Management.Match System.Text.RegularExpressions MatchCollection System.Text.RegularExpressions MD5CryptoServiceProvider System.Security.Cryptography MemberExpression System.Linq.Expressions
From .NET 3.5MemberInfo System.Reflection MemoryStream System.IO MethodBase System.Reflection Mutex System.Threading MutexSecurity System.Security.AccessControl NameValueCollection System.Collections.Specialized NetworkCredential System.Net Nullable System OdbcConnection System.Data.Odbc OdbcDataReader System.Data.Odbc OleDbCommand System.Data.OleDb OleDbConnection System.Data.OleDb OpenFileDialog System.Windows.Forms Page System.Web.UI PagesSection System.Web.Configuration ParameterDirection System.Data Pen System.Drawing Point System.Drawing PointF System.Drawing PrincipalContext System.DirectoryServices.AccountManagement ProcessInfo System.Web ProcessStartInfo System.Diagnostics PropertyInfo System.Reflection ProviderException System.Configuration.Provider Queue
as in Queue(Of ...System.Collections.Generic RC2CryptoServiceProvider System.Security.Cryptography ReadOnlyCollection System.Collections.ObjectModel Regex System.Text.RegularExpressions RegistryKey Microsoft.Win32 RijndaelManaged System.Security.Cryptography SafeFileHandle Microsoft.Win32.SafeHandles ScriptManager System.Web.UI
Note: Project needs a reference to System.Web.Extensions.SecureString System.Security SemaphoreSlim
From .NET 4.System.Threading SerializationInfo System.Runtime.Serialization Socket System.Net.Sockets SolidBrush System.Drawing SortedList
as in SortedList(Of ...System.Collections.Generic SpinLock
From .NET 4.System.Threading SqlCommand System.Data.SqlClient SqlConnection System.Data.SqlClient SqlTransaction System.Data.SqlClient SslPolicyErrors System.Net.Security StackFrame System.Diagnostics StackTrace System.Diagnostics STAThreadAttribute
as in <STAThreadAttribute ...System Stopwatch System.Diagnostics Stream System.IO StreamingContext System.Runtime.Serialization StreamReader System.IO StreamWriter System.IO StringBuilder System.Text StringCollection System.Collections.Specialized StringReader System.IO StringWriter System.IO StructLayout
as in <StructLayout ...System.Runtime.InteropServices SymmetricAlgorithm System.Security.Cryptography SyndicationFeed System.ServiceModel.Syndication
Note: Project needs a reference to System.ServiceModel.TcpClient System.Net.Sockets TextBox System.Web.UI.WebControls TextInfo System.Globalization TextReader System.IO Thread System.Threading ThreadAbortException System.Threading ThreadPriority System.Threading ToolboxData
as in <... ToolboxData ...System.Web.UI TripleDES System.Security.Cryptography TripleDESCryptoServiceProvider System.Security.Cryptography UpdateCheckInfo System.Deployment.Application UpdatePanel System.Web.UI
may also require a project reference to System.Web.ExtensionsUTF8Encoding System.Text Unit System.Web.UI.WebControls WebClient System.Net WebControl System.Web.UI.WebControls WebRequest System.Net Win32Exception System.ComponentModel WindowsIdentity System.Security.Principal WindowsPrincipal System.Security.Principal X509Certificate System.Security.Cryptography .X509Certificates X509Chain System.Security.Cryptography .X509Certificates XDocument System.Xml.Linq XElement System.Xml.Linq XmlDocument System.Xml XmlElement System.Xml XmlPreloadedResolver System.Xml.Resolvers XmlReader System.Xml XmlReaderSettings System.Xml XmlTextReader System.Xml XmlTextWriter System.Xml XslCompiledTransform System.Xml.Xsl ZipEntry Java.Util.Zip
Note: Project needs a reference to vjslib and server needs Visual J# runtime.ZipInputStream Java.Util.Zip
Note: Project needs a reference to vjslib and server needs Visual J# runtime.ZipOutputStream Java.Util.Zip
Note: Project needs a reference to vjslib and server needs Visual J# runtime.Zone System.Security.Policy I expect to add to this table over time.
- If the name is correct and the necessary namespace has been included then check the framework version. Not all classes and types are available for all frameworks. For example "SempahoreSlim" was introduced with the .Net framework 4, which means that you will get an error trying to use it if you are targeting a .NET framework earlier than the .NET 4 framework after including a reference to System.Threading.
These notes are believed to be correct for VB.Net and C# for .NET 1.1, .NET 2, .NET 3.5 and .NET 4, and may apply to other versions as well.
For the corresponding C# version of this article please see "The type or namespace name could not be found".
About the author: Brian Cryer is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.