Last post Dec 05, 2018 09:43 PM by Sam Hobbs
Dec 05, 2018 08:18 PM|Sam Hobbs|LINK
I just want to use a class in my web application and VS insists it does not exist but it does. This is a very basic problem and I have searched but I can't find something explaining what to do.
I have had a web site project for a few years and I want to add use of Entity Framework. I was having so many problems (that might be version related) that I decided to create a new project and I chose web application instead of web site.
I am using EF Code First. I had a DbContext class with the code file in the App_Code folder but as I see in Call a Class file in Asp.net Web Application I should not use the App_Code folder. I moved the DbContext
class file to the project root but the code that uses it can't find it, I get the error saying it could not be found. I try using Intellisense and I try finding it in the Class View. I tried rebuilding the solution. I don't see the class anywhere except in
it's file. The code is the same as for the web site project except for the differences described here.
Does that describe the situation well enough for you to explain what I need to do?
Dec 05, 2018 08:45 PM|mgebhard|LINK
Open the moved file in question. Copy the namespace line that surrounds the class. Paste the clipboard contents to the file that complains about the missing class. Finally, replace the word "namespace" with "using" if this is a C# app or "Imports" if
this is a VB.NET app.
By the way, there is nothing wrong with having an App_Code file in a web application. However, if this is really a Web Site then put the class back in the App_Code folder.
Dec 05, 2018 09:43 PM|Sam Hobbs|LINK
The namespace names are the same. I did as you said anyway except I added the semicolon. Does not help.
Note that if it was just a matter of adequate qualification then the class would be in the Class View somewhere, right?
I can't find it now but I did see a post that said that having an App_Code folder in a web application will cause the namespace to exist twice. I am not sure of the details but it is exactly what happened to me. However see App_Code
folder; the answer there says You shouldn't use App_Code in a Web Application Project at all.
See App_Code. Fortunately I found that among the long list of other threads. That was the
problem and solution. So I was doing everything right, VS messed me up in a way that was not obvious and I might have gotten a very long discussion here before anyone figured it out.