Custom Namespace on .NET web app - c#

So I wrote some custom classes and put them all in a namespace, call it "Sphere".
On my aspx.cs codebehind file, I have "using Sphere;" written. I know that this works because it's always worked until I copied this project to a new folder. Also, even when I click "view in web browser" everything works perfectly.
Simply, Visual Studio 08 is not recognizing the namespace and so I cannot build without an error and consequently cannot debug. Thanks for the help!
edit:
I have my namespace in my App_Code folder in a .cs file

Are your custom classes in a separate project? If so, you might need to add a reference to that project. If you have copied the project to a new folder, the path to your Sphere DLL/project in VS2008 might be broken.

I actually just figured it out:
My .cs files were set to "build action: content" rather than "compile." I right-clicked + properties all my files and changed the build action, and now it all works!

Sounds like missing reference.
In your new project, do you have a reference to the project that defines the actual Sphere namespace?

Check your references. It's possible VS is no longer finding them after you moved your application's folder.

It sounds like when you moved the files the references were broken. If the sphere classes are in a seperate dll try deleting and re-adding the reference. If it is just in a .de file be sure that filein the project is still in the relative path.

Probably you got this error:
The type or namespace name 'CustomClass' could not be found (are you missing a using directive or an assembly reference?)
And the reason the type was not in the assembly is that App_Code folder is specific folder for Web Site Projects. These files get compiled at runtime when they are deployed on server and not when you are building the project.
In Web Application Project every file has Build Action property. By default the classes files have value of Compile. But if the class is created in App_Code file it gets value Content. and does not get compiled when running as Application.
A the end the App_Code folder is not meant to be used in Web Application. Or as you figured it out you can manually change the Build Action to Compile.
I found the answer by searching these links:
Vishal Joshi's Tangent - App_Code folder doesn’t work with Web Application Projects (WAPs)
Build Action" property set to "Content" for class files inside App_Code folder

Related

Why isn't one c# class in one file not finding another one defined in another file/folder?

I’m working with a new ASP.Net project in Visual Studio 2019. I’ve imported two files that play nicely together in another project, but not in this one.
One file lives in the root folder and references a class that’s defined in another file, one that lives in a subfolder off of the root, App_Code. The problem is in the file off of the root – the reference to that other class has a red line under it. It says, “The name ‘blah-blah’ does not exist in the current context.” It’s not picking up the class defined in the App_Code folder.
Neither file has any namespace declared – they both just define their respective classes… Again, these two files play nicely in an older project, but not in this new one.
Any thoughts? Thanks for the help!
You might have space in folder name, that causes Visual Studio not to find the referenced file.

Renaming C# project to map to correct configuration

I have a created a C# console application that does something. Lets say its name is SampleTest. I use a config file named App.config in it. When I build this project, it creates files like SampleTest.exe, SampleTest.exe.config, etc. This is all fine.
My friend wants to execute this executable. So rather than sending SampleTest.exe and SampleTest.exe.config, I renamed the two files to DocumentManager.exe and DocumentManager.exe.config and gave it to him.
We noticed that this way, the DocumentManager.exe is not able to use the DocumentManager.exe.config file.
Please let us know what do I need to do in Visual Studio to this SampleTest project for it to generate DocumentManager.exe and DocumentManager.exe.config?
I tried renaming the SampleTest project to DocumentManager and building it but it still generates SampleTest.exe
Renaming the Assembly
Renaming the project on it's own is likely not going to be enough for what you are trying to accomplish. You'll need to ensure that you update the name of your assembly and namespace as well, which can be done through Properties > Application > Assembly name :
Changing the assembly name will change the names of your executable and .config files generated when building the project. It's probably worth changing your default namespace as well, just to keep things consistent.
You have to rename assembly. To fix this please do the following:
Navigate to project folder and find SampleTest.csproj file.
Open that file in some text editor like Notepad++. Find elements:
<RootNamespace>SampleTest</RootNamespace>
<AssemblyName>SampleTest</AssemblyName>
Rename their values into:
<RootNamespace>DocumentManager</RootNamespace>
<AssemblyName>DocumentManager</AssemblyName>`.
4. Build your project and you will see new DocumentManager.exe.config and new DocumentManager.exe files.
Or you can change Namespace and AssemblyName trough UI by navigating to Properties > Application > Assembly Name.

The type 'typename' exists in both App_Code.dll and solution.dll

I have a Visual Studio 2012 solution which includes a Web Application Project plus a number of Class Library Projects. The solution builds successfully in VS but when I browse to an ASPX page I get this error:
Compilation Error
S0433: The type '<type-name>' exists in both
'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root\3e98edf3\c4c22795\App_Code.dll' and
'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root\3e98edf3\c4c22795\assembly\dl3\ef67a753\a19c0f5f_801ecf01\
my-solution.DLL
My Web Application project does not contain an App_Code folder, only an AppCode (note the missing underscore) folder. I inherited this project from another developer so can't find out why it is setup this way.
I have tried clearing my temporary ASP.net files and have Cleaned and Rebuilt the solution.
Found the problem! When viewing through Windows Explorer, I had an AppCode and an App_Code folder with the same files in each. I guess whoever worked on this before me had created AppCode and somewhere along the way the new App_Code was added.
This is what caused the duplicate type name, one compiled into App_Code.dll and the other into solution.dll

dll classes can't access in app_code folder files

I am working on asp.net(3.5)
in my project there is one layer named app_code contain the business logic of the project
in this project I have added one reference file named Microsoft.ApplicationBlocks.Data
when I include namespace in default.aspx.cs file it works properly but when I work on the business logic class file which is in app_code folder I show compile time error.
I have not find any solution
please give solution....
thanks in advance....
add reference to that dll in your files like using <dllname>

How to find out where my error is coming from?

I have an annoying error that's been popping up, and I don't know where it is coming from. The error is:
Error 31 Unable to copy file "app.config" to "bin\Debug\Framework.Tests.dll.config". Could not find file 'app.config'. Framework.Tests
The problem is, I don't have a bin\Debug folder anywhere, and it does not say from where it is trying to copy app.config. Double clicking on the error doesn't bring me to any code where it is trying to copy, so that doesn't help me either. So I don't know where I should make the app.config.
How can I find this out?
You have added a reference to a file called app.config or Visual Studio did this for you. The file does not exist on the disk, presumably because after adding the reference you later deleted the file.
Search for the missing file in your Solution Explorer, and either delete the reference or create the file.
It is most likely in the root folder of one of your projects, and should have a yellow triangle warning icon showing that the file is missing.
In an MSTest project the app.config is the one that you would like to provide any calls to the ConfigurationManager class.
It resides in the root of your test project.
The bin\debug folders will be created once the project compiles for the first time. Show all files in the solution explorer should help as they are not (and should not) be included in the project.
HTH
You probably do have a bin\Debug folder beneath your project folder, being the build target folder created by Visual Studio when you build your project for the Debug configuration.
My guess is that something (a test framework perhaps) still has the DLL file loaded, so Visual Studio can't delete and replace the existing Framework.Tests.dll.config file with the contents of your app.config. [Note: the project build action for app.config files is to copy it to the target folder renamed to match the executable with an extension of .config appended.]

Categories

Resources