Cannot deploy Aspx website, App_code folder classes become unreadable - c#

I have recently finished creating my website, I have therefore come to the stage where I have to deploy it to a live server however when copying across, all of the App_Code, App_Data and Bin folder items become unaccessible. All of the classes are fine when I run on my dev server but once the files go across (exactly as they are) I can no longer create instances of objects from the App_code folder (very important).
The error I get is a quite generic error message.
CS0246: The type or namespace name 'Display' could not be found (are you missing a using directive or an assembly reference?)
I have never needed to declare a namespace for the code in App_Code before so I presume the error is not completely accurate. The permissions on files and folders are also the same.
When I use intelisense on the deployed website, it does recognise the objects. However once Comiled are not usable.
Any help would be much appreciated.

Do you have a missing refrence when you move to the new server?
Check your project's refrence folder and project settings. Make sure the .dlls are marked copy local and if your using anything from the GAC. If so you may need to deploy the .dll to the production server for things to work.

Are you manually copying the site's files (say, with an FTP client) or are you using the Copy Website tool ('Website' menu, `Copy Website...' menu item)? I'd hope the tool can help you get all the necessary files copied over neatly.
The error message you are seeing doesn't necessarily require namespaces; it's referring to a type with no namespace, or in one of the namespaces in your 'using' statements, called 'Display,' that you've referred to in one of your ASPX files. That;s pesumably one you've put in your App_Code folder. Don't worry about using namespaces.

I am using the VS2008 Copy Website function to deploy the website. I have not needed to have a using declaration before to access the app code I presumed it was always accessible from anywhere within the website.
How do I check the dll which you mentioned?

Related

Compiler Error Message: CS0246 [duplicate]

I have written a class called ArchivedFilesWrapper in the App_code folder of my project, however when I use this class in another file in a different folder i get error:
The type or namespace name 'ArchivedFilesWrapper' could not be found (are you missing a using directive or an assembly reference?)
I thought every page should be able to find classes that are contained within the same project, but I guess this is not the case. Can someone please tell me what using statement I need to have?
Here is a snippet from my class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EMCWebAdmin.App_Code
{
public class ArchivedFilesWrapper
{
Perhaps the problem will be solved by changing the Build Action Property of the *.cs source file to Compile from Content. From the Solution Explorer right click on the source file and choose Property.
Note that the App_Code folder is intended for use in Web Site Projects.
Note that for a Web Application Project or MVC project, adding an App_Code folder to your project and putting *.cs files in it will cause problems. I ignorantly added an App_Code folder to my MVC project from the Solution Explorer. VS defaulted the name space to MyProjectName.App_Code. In this case Visual Studio 2012 defaulted the Build Action to Content, even though the type was .cs code. After I changed Build Action Property of the *.cs source file to Compile from Content the namespace was resolved in other folder locations of the project. However because of problems, I had to change the name of folder--see below.
Important
In the MVC or Web Application project, the App_Code folder is trouble because it has Web Site Project type semantics. This folder is compiled when published (deployed) to the server. By changing Build Action from Content to Compile, you resolve the namespace issue on your development environment by forcing immediate compilation, but you get trouble when the second compilation results in objects defined twice errors on deployment. Put the code files in a folder with a different name. If you converted a Web Site to a Web Application, see the guidelines on the Net for this--not in the scope of this question. To read more about App_Code folder in the different project types see this blog
You need to add
using EMCWebAdmin.App_Code;
to all the pages you want to be able to use the class.
Alternatively you change the namesspace that the class is in to the same one that all the web pages use which presuming it is EMCWebAdmin
then in your class change
namespace EMCWebAdmin.App_Code
{
...
to
namespace EMCWebAdmin
{
...
This is a feature of visual studio, if you create a class in a folder structure, it uses a namespace that follows the folder structure.
If you convert it to a web app it should work. The downside is that it will no longer autobuild your code in app_code folder every time you change it and spin up the app. I have never seen a professional developer use a website project. I have no idea who MS were targeting when they created them.
Yes, put the calsses to another folder(not asp.net special folder), and only use the main namespace for the application is solve this issue.
Thanks johnmcp.

Type or namespace name does not exist in the namespace - yet the namespaces do exist

A project that I've been working on for a long time without any problems suddenly started throwing errors such as
The type or namespace name 'xxx' does not exist in the namespace 'yyy' (are you missing an assembly reference)?
In this case, the namespaces were all core .Net libraries such as System.Data, Linq, and IO that I've been using without any problems.
I've worked through all of the issues in this question such as making sure all the projects in the workspace are using the same version of .Net for the Target Framework setting.
I removed all the libraries in question and re-added them but the problem persisted. I doubt they libraries themselves are corrupted as I reference them in other projects within the solution.
After rolling back through my work with TFS I managed to work out what I'd done that had created this error: I'd added a folder called "System" to my project and put a class file in it.
This is an easy issue to reproduce: create a project, add a folder called system to it (it will still compile at this point) and then create a .cs file in it, that's when all the fun errors will occur.
The problem stems from the name of the "System" folder which leads to any files created in it being under the namespace ".System".
I can understand why having a folder / namespace called "System" would cause problems now but I think it would help if Visual Studio warned when creating a folder / namespace of such a name to stop this problem happening in the first place. I've logged a bug with MS, at least having this logged might help any other people who have made the same mistake as me!
I had the same issue after my system shut down unexpectedly and even though VS tried to restore, the problem popped up.
I had two projects in my Solution Explorer. To solve this, I right-clicked the project that was associated with the error message and selected 'Build'.
After that, the issue was resolved.
Just to add that the problem was permanently solved after I added a reference to the 'project' from the other 'project'.
I renamed the namespace of the file I was referencing from myproject.shared.constants to myproject.SOMETHING.shared.constants
After that It suggested "use myproject.SOMETHING.shared.constants" as suggestion. I renamed it back to myproject.shared.constants and then it worked.
Try to Clean and Then Rebuild the dll file .I was experiencing the same problem tried different suggestions from internet but none of them work.But it will. In case you don't know how follow these steps:
open your dll project file.
2.click on solution Explorer Right click on Your Dll Project Name you will find Clean and Rebuild Option.

Unable to find the type or namespace name after moving files

I get this error message in Visual Studio when I'm trying to run the C# code:
The type or namespace name 'Shape' could not be found (are you missing a using directive or an assembly reference?)
Is this because I changed the location of some files in the Solution Explorer? From the beginning I had the files in a folder and then I moved them outside and erased the folder. I have tried to use rebuild solution and clean, but I still get this error.
Now I have all files in the same "level" in the Solution Explorer. What can I do to get it to work again?
A few things to try:
Make sure the class file containing the Shape class is marked as "Include in project" in the Solution Explorer.
In the file with the error, make sure you have an appropriate using statement referencing the namespace where the Shape class is located.
If the Shape class is in an external DLL, make sure it is referenced in your project.
Double-check what the namespace is for the class file that contains the Shape class. Depending on how you moved those files around, it may have changed and you will need to update the using statement where you use it.
This can be caused by many things. e.g. public, assembly referencing, and in a project or a solution folder. JohnFx has already handled some of these in his reply. But to get you "going" do the following:
Move all of the files into the same project within the solution. So you solution has a project and all of the files are in that one project.
This should at least get you going. Then experiment.
Good luck.

WCF Service in Sharepoint 2010 can't find my Custom ServiceHostFactory class

I made a great WCF service in my dev environment, then when I pushed it up to production I got various errors saying "This collection already contains an address with scheme http..."
So, I created a Custom ServiceHostFactory class for my service.
Now when I upload it I get:
The CLR Type 'WCFServices.MultipleHostFactory' could not be loaded during
service compilation. Verify that this type is either defined in a source
file located in the application's \App_Code directory, contained in a
compiled assembly located in the application's \bin directory, or present in
an assembly installed in the Global Assembly Cache. Note that the type name
is case-sensitive and that the directories such as \App_Code and \bin must
be located in the application's root directory and cannot be nested in
subdirectories.
I checked the GAC and my assembly is indeed there.
Can anyone explain why this error is occuring?
Again, I am using .NET 3.5 on Sharepoint 2010
Is it "WCFServices.MultipleHostFactory" or "WCFServices.MultipleHostsFactory"? If its the first, thats why because that namespace does not match that you said in your question.
It turns out that I was able to remove one of the bindings from the application host configuration file. After talking with the administrator, I found that he had two bindings for port 80. One was IP:80:[DNS name] and the other was :80:
We agreed to get rid of the :80: binding and the WCF service was able to deploy to SP.
If anyone ever runs into that CLR loading issue, please post with a solution. I still don't have a good explanation for that problem.

asp.NET 2.0 Web Site Can't Access Classes in App_Code

I'm having a problem accessing a class after deploying my website to a server.
Note that this is a Web Site not Web Application.The error is:
Compiler Error Message: CS0246: The type or namespace name 'Order' could not be found (are you missing a using directive or an assembly reference?)
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
I've done a lot of googling and haven't been able to find anything that helps.
My code looks like this (I get the compiler error on the line declaring Order):
//Default.aspx.cs
namespace Foo
{
public partial class _Default : System.Web.UI.Page
{
private Order custOrder;
....etc
}
}
In the App_Code folder I have Order.cs:
namespace Foo
{
public class Order
{
....etc
}
}
The strange thing is that this works fine locally and in a dev environment. When I move it to a qa environment, that's when I get that error.
I deploy by committing all the code to a subversion repository and then doing an export on the server machines.
I guess it could be some kind of namespace error, but I don't know why it would work on some machines and not others.
Any idea what could be different on a different server that might cause this? All machines report the .net version as 2.0
Right click the source file in App_Code and set its "Build Action" property to "Compile".
As it says, the error means that it couldn't find that type.
Possible causes:
A compilation error prevented the .cs files in your app_code folder from being compiled. When ASP.NET looks at the compiled code, it can't find the class you're looking for, thus the error.
The .cs files weren't deployed to app_code. Obviously if the source files aren't in the site, they can't be compiled.
A permissions issue is preventing the server from loading the .cs files.
One of your pages is incorrectly referencing the class - perhaps a typo in the .cs or the .aspx, a class moved to a new namespace or renamed, etc.
Essentially, the source couldn't be found, accessed or compiled.
A lot of times the bin directory is ignored in SVN (for good reason) so what ends up happening is that locally (when debugging) VS takes care of creating the App_Code.dll for you. What you will need to do is check to see if the bin directory is deployed to your server machines. If it isn't you have many ways to deploy your solution, by using deploy website, or ftp copy, etc.
Is the property Build Action set to Compile on your App_Code files ? It is not by default on Web Application Projects.
Are you deploying the .dll within your .aspx file?

Categories

Resources