Class File In App_Code Folder Not Working – ASP.NET MVC

Today, we have started to migrate the website (ASP.NET 2.0 Website) to ASP.NET MVC. As per the standard practice, we have created a class and put it inside of the App_Code folder in ASP.NET MVC 4.0. However, we cannot access it from controller.

After getting some research,

  1. App_Code folder is a special ASP.NET run-time folder
  2. All MVC project is Web Application Projects (WAP) instead of Web Site projects. This means that there’s no need for an App_Code folder since WAPs always get compiled anyway. That means that all *.cs files in your project will get compiled, as opposed to Web Site projects where only *.cs files in your App_Code folder would get compiled.

Solution:

  1. Go to App_Code folder – right click on the .cs file and check the property
  2. Set “Build Action” is set to “Compile”
  3. Build the solution and its working fine.

solution

Happy Programming!!

Leave a Reply

Discover more from The Engineering Behind Enterprise AI

Subscribe now to keep reading and get access to the full archive.

Continue reading