Visual Studio is not recognizing new classes
Asked Answered
H

7

19

I'm using visual studio 2008 SP1, I'm working with a web project in VB.NET. the problem when I add new class file (of-course in App_Code) it doesn't recognize it. all the old class files are working fine, but the new ones aren't. I restarted my computer and still the same problem.

Any Ideas

Handsel answered 2/12, 2009 at 13:10 Comment(0)
D
48

compare properties of working class with un recognised class. Specifically, "Build Action". It should resolve the problem.

if not let me know. :)

Dovetail answered 2/12, 2009 at 14:9 Comment(3)
THANK YOU! I know it's years later, but this will still happen (currently using VS2013 Update 4), more specifically in asp.net projects when createing custom plain classes. The Build Action needs to be Compile.Nataline
vs2013update5, although my issue wasn't the Build Action but the target framework. I had created a new class library and the framework was targetting 4.5.1 instead of 4.5 as the other projects.Shoreless
Wow, thank you! I still see this issue in VS 2019. Why is it not always the default to set a code file build action as compile and not content? Makes no sense. Btw, to find the build action, right click on your class you added in the solution explorer.Judiejudith
M
2

If there is a solution involved, try "rebuilding" the entire solution. Rebuilding projects and websites individually didn't do it for me - after trying other suggestions here only the project rebuild worked.

Mcadoo answered 21/2, 2011 at 23:22 Comment(0)
A
1

Make sure it is in the same namespace as the thing you are trying to call it from, or fully declare using the namespace when creating one. Perhaps also give us an example of one that works and one that doesn't.

Also, don't forget to use the proper access modifier. Start with Public to see if that fixes your problem. If that does then your classes are almost certainly in different namespaces.

Ambagious answered 2/12, 2009 at 13:15 Comment(1)
The whole class doesn't work, even intellisense doesn't work inside the class itself, and I'm 100% sure about the namespace. yesterday when I add a class works fine, today just stopped workingHandsel
O
1

A made a small checklist bases on answer (also what I would do)

  1. Access modifier of a class must be Public or Friend. Read more here
Public Class MyClass

End Class
  1. Namespace The class you are trying to access to must be either in the same namespace or Imported via the keyword Imports YourNamespace.MyFeature Read more here

  2. A vb class must be set to compile in its build action. The option wont be available if your are in debug / running mode. To check this you need to: Right click on MyClass.vb -> Property -> Build Action -> Compile.

  3. If these steps didn't work you could try to clean project/solution, close and reopen VS, then re-build project/solution.

Hope it help!

Outreach answered 5/6, 2020 at 13:37 Comment(0)
T
1

Sometimes, a simple Clean and Rebuild of the project will resolve the issue.

I was refactoring a non-object-oriented C++ code to an object-oriented one. So, I think Visual Studio was confused at that point and the solution I mentioned worked for me.

Ticon answered 24/5, 2021 at 11:17 Comment(0)
P
0

maybe you are trying to use internal classes from another assembly or there may be problems with the access modifiers of the class.

Purusha answered 2/12, 2009 at 14:24 Comment(0)
E
0

I solved it by modifying visual studio installation (Tools-> Get Tools and Features). (From the right pane) I selected .net framework developlment tools. After installation is done I opened the project again and everything was ok.

Exhibitive answered 31/1 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.