I have create a new empty web application in c# Asp.net 4.0 and then added App_Code folder then added 3 classes into that folder. I have added a web user control and set the reference of App_Code class into the control but it throws an error.
The type or namespace name 'App_Code' does not exist in the namespace (are you missing an assembly reference?)
Any ideas?
This point can be confusing.
A "web application project" is not expecting the App_Code folder.
A "website project" would expect that folder and know how to use it.
Whether you realize it or not (and depending upon which version of Visual Studio you use), you will get a WAP or a WSP when you first create your web solution. They are different. It takes some effort to convert from one to the other.
Here are a few articles explaining the differences.
To solve your immediate problem, then, you can just move the 3 class files out of the App_Code folder into the root folder, or better, create a new folder to contain those classes and move them into it. Depending upon whether you give the classes in that folder namespaces, you may have to add a reference to that namespace in your UserControl.
Did you create the App_Code folder manually?
I was the impression the folder was created automaticaly when creating the project.
If not, when you add something to the project you select Add ASP folder, and it would have App_Code option along others there.
If the option isn't there is probably because you created a Web Application.
This might help you more: http://vishaljoshi.blogspot.com/2009/07/appcode-folder-doesnt-work-with-web.html
Related
I am using VS2019 Community Edition and have created a C# Console App solution in one instance of VS2019 and a C# Shared Project in another.
I have added a class to the Shared Project and then want to reference this shared project in the other project, so I right-click the References and choose to Add reference, then choose Shared Projects. The resulting window shows an empty list. Am I doing something wrong?
Other questions I have found suggest that the wrong Shared Project was created, i.e. using the wrong language, but I have checked and mine are indeed both C# projects.
The other suggested methods were to add it to the project manually by editing the .csproj file, which didn't work either, or something to do with MS Build config which is more than I want to get involved with.
Is it me or VS2019?
UPDATE 1:
So I managed to kind of fudge it, buy adding the Shared Project to the same project as the console project, but storing it in a different folder and reusing the .sln solution file to load it as a solution in VS2019. Progress, but even though I can add it as a reference, it doesn't seem to know about the classes in the Shared Project, even with a using reference.
This site was developed a few years ago. it was working 100%. I am re-deploying to my pc to make some changes and testing. Now it cannot find those classes in those files. I have always used 4.5 Framework. I have searched for a solution, unfortunately those have not resolved my issue. including coping it into main directory. It worked when I copied the actual code into one of the *.cs.aspx files. However there are more then 20 pages using this email file. Any advice would be welcome. I have been scratching around for days. Thx.
===================ERROR========================>
The error is as follows:The type or namespace name 'Emailer' could not be found (are you missing a using directive or an assembly reference?)
===================ERROR-DISPLAY================>
Source Error:
Heading
As the message is saying you are most likely missing an Assembly reference. Look at the references of the old project (pic below) and make sure your new project has the same ones added.
If you locate any missing references you can add them by clicking on References > Add reference, and find it among the listed ones or browse to the physical path.
Go to class property window by right clicking on it. Look for build option here Change your class build option to compile.
You probably changed a Web Site Project to a Web Application Project. There are a couple of differences between these project types. Among them, in Web Application Projects, the App_Code directory seems to be ignored.
I am building this project and i have an external dll . I want to add a reference to it from the root reference folder . I have not tried though if its wrong.
But there is an obvious answer to this question across internet stating i have to referenc e the dll in the web.config assembly file .
I want to know why do we need to do so?
what is the differences between both ways ?
in the web.config section
The assemblies element defines a collection of assembly names that are
used during compilation of an ASP.NET application.
The assemblies element us usually used in web site projects as there is no project file storing location of references that the web site uses. The project references would not apply to a web site, as it has no proper project file to store these in, so must store all referenced assemblies in the web.config. There is some interesting, although not directly related, discussion here. In a web application project you can use both the assemblies element and project references.
Having a reference in the assemblies element also means you won't have to add the #register at the top of any .aspx pages that use that namespace. More discussion on that here.
So I'm trying to access a couple of IsInteger/IsNumeric functions from a custom class library I wrote in a separate project but within the same MVC4 solution.
I have a class library called MyHelpers (class library project) and the other is called Portal (a web application project), so two separate projects in the same MVC4 solution. After building MyHelpers successfully and putting the .dll in the Portal project's bin folder AND adding a reference to MyHelpers.dll, I still cannot find a reference to it in my Controller .cs file when adding the "using MyHelpers;" statement.
Why is this happening? Am I missing something? I thought that if I add a reference to the .dll and use the "using" statement it will let me reference the functions in the class library. What gives?
Please help and thanks much in advance.
In your MVC4 project, add a reference to your MyHelpers project. This way when you build MyHelpers again, your MVC4 project will have the most updated build of the MyHelpers.dll in the bin directory. You should not simply just reference the dll directly unless you have changed your output directory to the MVC4 project's bin directory. Be sure to check your output directories and make sure that all necessary dlls are in the directory of your MVC4 application.
I want to organize my solution by adding folders and organize classes into them
how to access these classes as i tried to access them but can't
folders looks like packages in java
When you create a folder in the Visual C# project it normally creates a namespace for items created in that folder. You need to add a using blah.foldername statement to the c# file where you are trying to use the items from the folder, or you can edit the file in the folder to use namespace blah instead of namespace blah.folder.
Visual Studio mimics your project's hierarchy on the hard drive. When you add a solution folder within Visual Studio, it creates a real folder under your project directory. Any new projects or source files you add to the solution folder in Visual Studio will default to that directory. Also, and this gets to the heart of your question, when you add a C# file, i.e., class, to the solution folder, Visual Studio places it in a sub-namespace of your project.
For example, if your project is named MyProject, the default namespace will be MyProject. If you add a solution folder to MyProject called MyFolder, any new files, i.e., classes added to that folder from within Visual Studio will have a default namespace of MyProject.MyFolder. Thus, in order for classes in the MyProject namespace to reference classes in the MyProject.MyFolder namespace, you need to either fully qualify the class name, e.g., MyProject.MyFolder.MyClass or include a using MyProject.MyFolder; statement at the top of file where the class is used.
If you are asking about solution folders, they don't translate to the resulting code. They are merely a way to organize your projects.
If you are creating folders in your project to separate code files, then traditionally we would have the namespace represent the hierarchical structure of the solution/project.
Then you just include the namespaces as you normally would.
Does this answer your question?