Error BC30451 'xxxxxxx' is not declared. It may be inaccessible due to its protection level

David Anderson 206 Reputation points
2021-08-27T09:51:40.103+00:00

I am in the middle of updating a .NET 4.7 Web Application project (based on VB.NET) to add code for processing incoming payments via PayPal. This code is being imported from an older Web Site project.

I am aware of most of the differences between a Web Application and a Web Site project and have successfully converted all my aspx pages to the new format. However, I am hitting an unexpected problem with a set of utility programs contained in a class called MiscCode. This class is saved in a file called MyCode.vb, which is stored in the App_Code folder on my Web Site project.

Public Class MiscCode

    Public Shared Function xxxxxxxxx()
        'Code
    End Function

    Public Shared Function zzzzz()
        'Code
    End Function

End Class

I imported this 'as is' to my Web Application, but when I try to make any reference to the functions in the MiscCode class I get the following error.

  • BC30451 'MiscCode' is not declared. It may be inaccessible due to its protection level

I tried adding 'Imports MiscCode' to the top of the relevant page, but this generated two other errors. Firstly, that this Imports statement was unnecessary and the following error.

  • BC40056: Namespace or type specified in the Imports 'MiscCode' doesn't contain any public member or cannot be found

Moving MyCode.vb to the root of my Web Application project made no difference and, so far, my searches for assistance with the BC30451 error have not helped. Some guidance would be much appreciated.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,405 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,659 questions
{count} vote

Accepted answer
  1. David Anderson 206 Reputation points
    2021-08-27T13:15:56.653+00:00

    I've found a solution!

    Just as an experiment, I used Add > New Item > Visual Basic > Code to add an empty class definition to my new MyAppCode folder. This displayed a drop down item of the same name below the new vb file. Hovering over the icon associated with this drop down item displayed a pop-up showing the name of the new class prefixed by my project name.

    This drop down was not shown for my original MyCode.vb file, so I copied my code into the newly created class. After a rebuild my BC30451 error disappeared.

    I have thus learned about another area in which a Web Application differs from a Web Site :)

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. David Anderson 206 Reputation points
    2021-08-27T13:49:03.69+00:00

    As another experiment, I recreated the App_Code folder and then transferred the new version of MyCode.vb to that folder. After another rebuild, the BC30451 error reappeared. This confirms that Web Applications do not treat App_Code as a normal folder.

    I have now reverted to storing MyCode.vb in the MyAppCode folder.

    0 comments No comments