Issue With References Being Resolved - c#

I've built a project with ASP.NET using C# and the project worked perfectly fine in the VS13 environment, but when put on IIS it's been nothing but frustrating. The structure of the project utilizes MVC, and as such uses directories in the project for each the Models, Controllers, and Views.
In the Master Page, I'm calling two references:
TrailerWizardsPortal.Models
TrailerWizardsPortal.Controllers
The Issue:
When I run a page that uses the Master Page, the project breaks because of these references. Some additional information that may help one better understand:
Framework 4.5 is used in the project and in IIS, and is installed on the server
The Master Page front-end has been changed from CodeBehind to CodeFile
IIS is version 8.5
Output:
The output is the standard "Compilation Error" that the type or namespace doesn't exist. In this case, 'Controllers' and 'Models' both are culprits.
How could I go about having IIS realize that these directories exist?
Error:
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 'Controllers' does not exist in the namespace 'TrailerWizardsPortal' (are you missing an assembly reference?)
Line 7: using System.Configuration;
Line 8: using TrailerWizardsPortal;
Line 9: using TrailerWizardsPortal.Controllers; ← the line that breaks
Line 10: using TrailerWizardsPortal.Models;
Line 11: using System.Web.UI.WebControls;
'Controllers' and 'Models' are both located in the location as specified by the using statements.

I finally figured out my issue. I had to convert my 'Website' directory to be an application. Here's the steps I had to follow:
Open IIS Manager
Expand the site you wish to work on
Right-click on the 'Website' directory (this may be named something else for you - the directory which contains all your .aspx and .cs files) and choose 'Convert to Application'
Fill the fields accordingly to your configuration and click OK
Keep in mind this was an ASP.NET web application, so this may or may not be a resolution for you.
Seems like a rookie mistake, but that's what fixed it for me. Hope this helps someone out.

Related

CodeFile and missing using directive or assembly reference

I have a very old ASP Classic site I need to maintain and I'm trying to convert a feature that generated robust Excel & Word files using old ActiveX controls by using ASP.NET CodeFile files instead.
I'm more a MVC person and don't know much about web forms, but was able to build a working example of an excel report as a CodeBehind file and referencing EPPlus. Okay so far, however when I try switching the *.aspx page to CodeFile, I get a compilation error with line 6 of my *.aspx.cs file:
CS0246: The type or namespace name 'OfficeOpenXml' could not be found
(are you missing a using directive or an assembly reference?)
Line 4: using System.Drawing;
Line 5: using System.Globalization;
Line 6: using OfficeOpenXml; <-- error here
Line 7: using OfficeOpenXml.Style;
What am I'm missing about CodeFile? Is this not possible?
AFAIK the CodeFile method is what I want because it will let me seamlessly add the files to my existing ASP Classic site while going with CodeBehind will require hosting the project as a separate application. See self-answer
Okay I figured out my issue following #शेखर's line of questioning. I have essentially two projects. One is a plain asp classic web site and another is an actual .NET web forms application. My problem was the location of the bin folder with my dll. The bin folder needs to be a the root level of my asp classic web site regardless of where my .NET files are hosted within that site.
Also I'm pretty sure I am wrong about my AFAIK in my original question. You should be good with CodeBehind provided your project's dll is also in the bin folder at the root level. This might not make sense though if your classic site hosts unrelated "applications" separated into different folders at the root.
I'll keep this up in case another might find it useful or until it's suggested I take it down.
Thank you #शेखर for keeping me pointed in the right direction.

VS 2017 doesn't recognize assembly name after renaming it in ASP.NET

I have 2 projects: Domain - library project and WebUI - Asp.Net project. WebUI depends on Domain.
I've tried to rename solution name of my project and now I'm getting this error in my browser, when I'm trying to start Asp.Net Application.
Server Error in '/' Application.
An error occurred during the compilation of a resource required to
service this request.
CS0246: The type or namespace name 'SolutionName' could not be found
(are you missing a using directive or an assembly reference?)
Source File: C:\Users\user\AppData\Local\Temp\Temporary ASP.NET
Files\vs\7c2cf4c9\4c15470e\App_Web_default.cshtml.6373d792.ysrztpbf.0.cs
Line 27: using SolutionName.Domain;
I renamed every single occurrence of OldSolutionName to SolutionName. I removed the bin directory. I also followed this Proper way to rename solution (and directories) in Visual Studio . What should I do in this situation to repair my project?
EDIT
I have resolved the problem by changing SolutionName to NewSolutionName.
But still no idea what was the problem.

How do I get System.Web.UI.DataVisualization.Charting dll into WebMatrix 3?

I want to use the full charting options available in ASP.NET Web Pages in WebMatrix 3.
I think this means using System.Web.UI.DataVisualization.Charting
When adding:
using System.Web.UI.DataVisualization.Charting
to the top of my page, I get the error:
Compiler Error Message: CS0234: The type or namespace name 'DataVisualization' does not exist in the namespace 'System.Web.UI' (are you missing an assembly reference?)
There are plenty of tutorials out there (including on SO) demonstrating how to download and reference the dll into Visual Studio, but as far as I can see there's nothing for us WebMatrix users.
Does this mean that it can't be used in a WebMatrix site? If so, why??
If anyone knows how to include the relevant namespace in WM, I'd be very grateful if you'd explain it here.
WebMatrix doesn't provide a mechanism for adding references. However, you can work around this by right clicking on the bin folder and choosing Add Existing File. Then you need to locate System.Web.Datavizualization.dll, which on my machine is located in C:\Windows\Microsoft.NET\Framework\v4.0.30319. Once you have a copy of that dll in your bin folder, you are in business.
I would however recommend moving across to Visual Studio. Then it's simply a case of using File » Open » Web Site to open your WebMatrix site folder.

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.

The type or namespace name 'Transactions' does not exist in the namespace 'System' (are you missing an assembly reference?) - C# ASP.NET

We have a C# ASP.NET Web Application that uses the System.Transactions namespace.
using System.Transactions;
This works fine when developing locally - we just had to add the reference first by going to Website --> Add Reference...
The problem is that after deploying to the web host (copying over FTP), the host doesn't know this reference.
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 'Transactions' does not exist in the namespace 'System' (are you missing an assembly reference?)
Working in Visual Web Developer Express 2010, we don't have the References folder built in. I saw this solution: https://stackoverflow.com/a/13035466/2178080 that suggests (but doesn't recommend) copying a dll to the application folder.
I'm a bit new to deploying with ASP and not sure how to include the System.Transactions library so the host can find the reference. Has anyone run into this issue?
Edit: We went with the route of copying the dll to the site along with the application. The steps to do this:
Copy the System.Transactions.dll from the local system.
Paste into the Bin folder.
The objects referenced in this assembly must now use the fully qualified name.
As this solution is listed as not recommended, I am still open to other solutions.
Edit2: Grant and Chris helped me understand that I was working with a Web Site and not a Web Application. Grant helped with the specifics of the Web Site problem.
Your problem is due to the published site is not bringing the System.Transactions.dll along with it, this points to "Copy Local" being set to False and thus the DLL not copying to the bin folder.
Go to References -> System.Transactions and make sure on the properties for this reference that "Copy Local" is set to True.
Check the target framework in IIS, make sure it's set to the same version of .Net that you are compiling your code in. If you are using IIS 7+, which have Application Pools, make sure the pool the application is running on is the same version of .Net.

Categories

Resources