BC30451: Name '<name>' is not declared

A statement refers to a programming element, but the compiler cannot find an element with that exact name.

Error ID: BC30451

To correct this error

  1. Check the spelling of the name in the referring statement. Visual Basic is case-insensitive, but any other variation in the spelling is regarded as a completely different name. Note that the underscore (_) is part of the name and therefore part of the spelling.

  2. Check that you have the member access operator (.) between an object and its member. For example, if you have a TextBox control named TextBox1, to access its Text property you should type TextBox1.Text. If instead you type TextBox1Text, you have created a different name.

  3. If the spelling is correct and the syntax of any object member access is correct, verify that the element has been declared. For more information, see Declared Elements.

  4. If the programming element has been declared, check that it is in scope. If the referring statement is outside the region declaring the programming element, you might need to qualify the element name. For more information, see Scope in Visual Basic.

  5. If you are not using a fully qualified type or type and member name (for example, your code refers to a property as MethodInfo.Name instead of System.Reflection.MethodInfo.Name), add an Imports statement.

  6. If you are attempting to compile an SDK-style project (a project with a *.vbproj file that begins with the line <Project Sdk="Microsoft.NET.Sdk">), and the error message refers to a type or member in the Microsoft.VisualBasic.dll assembly, configure your application to compile with a reference to the Visual Basic Runtime Library. By default, a subset of the library is embedded in your assembly in an SDK-style project.

    For example, the following example fails to compile because the Microsoft.VisualBasic.CompilerServices.Conversions.ChangeType method cannot be found. It is not embedded in the subset of the Visual Basic Runtime included with your application.

    Imports Microsoft.VisualBasic.CompilerServices
    
    Public Module Example
        Sub Main(args As String())
            Dim originalValue As String = args(0)
            Dim t As Type = GetType(Int32)
            Dim i As Int32 = Conversions.ChangeType(originalValue, t)
            Console.WriteLine($"'{originalValue}' --> {i}")
        End Sub
    End Module
    

    To address this error, add the <VBRuntime>Default</VBRuntime> element to the projects <PropertyGroup> section, as the following Visual Basic project file shows.

    <Project Sdk="Microsoft.NET.Sdk">
      <ItemGroup>
          <Reference Include="Microsoft.VisualBasic" />
        </ItemGroup>
      <PropertyGroup>
        <VBRuntime>Default</VBRuntime>
        <OutputType>Exe</OutputType>
        <RootNamespace>vbruntime</RootNamespace>
        <TargetFramework>net472</TargetFramework>
      </PropertyGroup>
    
    </Project>
    

See also