Cannot find classes once ASP.NET website is hosted - c#

My project is an ASP.Net website that connects to an SQL database.
It compiles fine locally in Visual Studio, but once it is hosted (myWindowsHosting.com) it throws this error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'IDefaultView' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 9: namespace HFDB2
Line 10: {
Line 11: public partial class Default : System.Web.UI.Page, IDefaultView
Line 12: {
Line 13: public event EventHandler btnNextClicked;
In this example I am trying to implement an Interface to the Default webform. But a similar error occurs for any class I try to reference.
Why cant my project find any classes once it is hosted?
Does it have anything to do with my folder structure?
My classes are not in an App_Code folder because apparently you dont need one for websites. I tried putting them in an App_Code folder anyway, but it gave a different error.
Note that I uploaded everything you see inside my project folder to the host.

I was deploying my application incorrectly. As Ben Robinson's comment says:
Never deploy source code. The easiest way of creating your collection of files to deploy is to use the Publish option in visual studio.

Related

Add .cs file to ASP Web Site project

I am working on an ASP.NET website and as part of the website I created a file called Global.cs which is used to hold all my helper classes. However, unfortunately, I am constantly getting errors saying there has been a problem while compiling this file. All the classes inside the file are included in single namespace - "Global".
When using it 'inline' eg. Global.SomeStaticClass.Method() :
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Global' does not exist in the current context
When using "using Global;" directive:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'Global' could not be found (are you missing a using directive or an assembly reference?)
As suggested in many posts, I tried including the class in App_Code folder of my project and the namespace, "Global", is detected by the Visual Studio (no errors when adding "using Global;" directive, or when using it inline "Global.Class.Method()". However, it still fails whenever I try to access the page in the browser.
I could not find a simple solution to my problem and decided that the easiest and the most time efficient solution will be to convert my Website project to a Web Application project. You can read how to convert your Website to a Web Application at: https://blogs.msdn.microsoft.com/webdev/2009/10/29/converting-a-web-site-project-to-a-web-application-project/
With the project converted to a Web App I was able to attach my class files after compiling them to a DLL library, as it did not accept any uncompiled files inside App_Code folder by throwing an exception.
The directory '/website/App_Code/' is not allowed because the application is precompiled.
If you encounter the same issue, you can learn how to compile C# files using Developer Command Prompt here: https://msdn.microsoft.com/en-us/library/78f4aasd.aspx

App_code codefiles unaccessable when "web site" is published

When I test my web site (asp.net c# .net4) on the localhost, everything works fine.
However, when I publish it to my webserver, I get the error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'MyWhateverNamedHere' could not be found (are you missing a using directive or an assembly reference?)
My code file (MyWhateverNamedHere.cs) lives in my App_Code folder, which IS moved to the webserver.
I have read where people move codefiles out of the App_Code folder. Didn't work for me. I tried giving them namespaces, and static references and just about everything I can think of. Then I found a solution that said Build Phases > Compile. But that's not an option for "web sites".
Any help?

Removed DLL causing runtime error

I have an ASP.NET web application built in visual studio 2013, .NET framework 4.5.1. The app used to reference a 3rd party dll, but I have refactored the program so it is no longer needed. I have removed the dll from the references and confirmed it is not being used anywhere in the solution. The solution builds just fine.
The problem comes when I try to run it. I get the familiar ASP white screen of death indicating that it cannot find the Namespace. The screen shows that the error occurs in a file in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ that seems to be generated at runtime. I don't know why or how this file is generated, or why it is still referencing the removed dll.
The Error:
Compiler Error Message: CS0234: The type or namespace name 'Web' does not exist in the namespace 'Telecom' (are you missing an assembly reference?)
Source Error:
Line 17: public class ProfileCommon : System.Web.Profile.ProfileBase {
Line 18:
Line 19: public virtual Telecom.Web.Modules.Common.Code.Preferences Preferences {
Line 20: get {
Line 21: return ((Telecom.Web.Modules.Common.Code.Preferences (this.GetPropertyValue("Preferences")));
Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\sso\8bcf3ae8\e33c1692\App_Code.zywjwlv-.0.cs Line: 19

Type or namespace could not be found, not client profile issue

I am trying to create a web application. It runs fine on localhost but I keep running into this error when I try it on the test server. I have looked through other questions off and on for a few days and tried all kinds of solutions but still no luck with the error
Compiler Error Message: CS0246: The type or namespace name 'courseDBLibrary' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 6: using System.Diagnostics;
Line 7: using System.Collections;
Line 8: using courseDBLibrary;
Line 9:
Line 10: public partial class Charts : System.Web.UI.Page
courseDBLibrary is the namespace in a referenced dll file. The dll contains 2 separate c# files, each with their own class, under the same namespace. The dll was added through the add reference dialog.
Originally the dll is placed in the bin at the root of the project, but when putting it on the server I have moved the bin folder to the wwwroot folder.
Finally, the dll is not using the client profile framework(aka is using .NET Framework 3.5)
The files in the DLL look like this
namespace courseDBLibrary {
public class class1 {
..
and
namespace courseDBLibrary {
public class class2 {
..
The file that throws the error is a fairly complex aspx file with c# code behind but, as you can see, the compiler is not even reaching the class part.
Any ideas would be greatly appreciated.

Does Microsoft.ServiceModel.Web only work in the GAC?

I created my first WCF RESTful service with just one GetData, and it works perfectly in localhost, but when I add it to a hosting environment, I get:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0234: The type or namespace name 'ServiceModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Does this mean that I need to place the DLL file in the GAC to this work? Shouldn't it work in the BIN folder of my service?
Here is how my service folder looks like:
Service.svc
Service.svc.cs
web.config
BIN
Microsoft.ServiceModel.Web.dll
Microsoft.ServiceModel.Web.pdb
MyService.dll
MyService.pdb
PROPERTIES
AssemblyInfo.cs
What can I do in order to make this work?
I had the same problem when I first tried to create a virtual directory directly in IIS 7.5, prior to publishing my RESTful web service to this folder.
The solution for me was to use Visual Studio 2008 (Project Properties / Web tab / "Use IIS Server") to choose the folder, and then the "Create Virtual Directory" button on the same tab to create the virtual directory. Everything then worked OK.

Categories