Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual Studio Unable to resolve references in aspx file

Posted on 2016-11-03
12
Medium Priority
?
28 Views
Last Modified: 2016-11-09
I'm using Visual Studio 2015.

I have a stand-alone aspx file with all the code in the ASPX file - there isn't a code behind file.

The file itself runs fine, but when I edit it in Visual Studio, Visual Studio underlines in red all the types - like Session, everything - although I have "import" statements at the top of the file it doesn't seem to know how to resolve them.

Any idea how to fix this?
0
Comment
Question by:purplesoup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
12 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41873304
can you post your scripts here? it helps us to diagnose your issues.
0
 

Author Comment

by:purplesoup
ID: 41873465
OK well I'll just show a little to give you an idea, but it is just a regular aspx page with code on the page. My issue is Visual Studio just underlines all the types (e.g. Session) in red - I don't see the point of showing the whole thing it is 300 lines and uses types you don't have anyway:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="XXXX.UI.DisplayPageBase" MasterPageFile="~/Templates/MasterPages/XXXX.master" %>
<%@ Import Namespace="XXXX" %>
<%@ Import Namespace="YYYY" %>
<%@ Import Namespace="AAAA" %>

<script language="C#" runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        ClearMessage();
        LogMessage("page loaded");
        try {
            if (Session["ConnectionString"] == null) {
                var connStr = ConfigurationManager.ConnectionStrings["DataSource.TEST.Connection"].ConnectionString;
                Session["ConnectionString"] = connStr;
                LogMessage("Saved Connection String " + connStr);
            }
        }
        catch (Exception ex){
            AddUserMessage(new UserControlMessage(UserControlMessageTypes.Error,ex.Message));
        }
    }
</script>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="TemplateBody">
    <div>
        <hr />
        <h3>Billing Cycle</h3>
        <asp:ListBox ID="BillingCycle" runat="server">
			<asp:ListItem Text="Company Regular Membership" />
			<asp:ListItem Text="List Billing" />
			<asp:ListItem Text="Referral Billing" />
			<asp:ListItem Text="Regular Membership Fees" />
			<asp:ListItem Text="Student Membership Fees" />
        </asp:ListBox>
    </div>
</asp:Content>	

Open in new window

0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41873494
Seems ok for me... what if you "Rebuild" (menu Build > Rebuild) your solution? will that red highlighting gone?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:purplesoup
ID: 41873500
No if I build it just gives lots of errors that the types can't be found.

But as I say the file itself does run ok - I just have it in the root of my website and it works fine, it is just Visual Studio doesn't seem to be able to resolve the references.

The thing is, it is a stand alone file - it isn't linked to any projects or solutions because it is just one file, it may be that Visual Studio can't cope with that and *has* to have the project/solution structure or something more than just the file to resolve references.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41873502
No if I build it just gives lots of errors that the types can't be found.
but from your codes it seems that the page is using a Master template file?

anyway... try to create a new project and put your page file in, and see if Visual Studio still behave the same?
0
 

Author Comment

by:purplesoup
ID: 41873788
ok I'll see what happens - would just have been nice to open a file and have it work... :(
0
 

Author Comment

by:purplesoup
ID: 41873807
ok - well if I try and fully qualify the reference - so for example:

HttpContext.Session["ConnectionString"]

it tells me (if I hover over) :

An object reference is required for the non-static field. method of property 'HttpContext.Session'

Otherwise it just says it can't resolve "Session" if you hover over it.

And just to repeat - the code runs fine, this is just Visual Studio giving me a lot of red-underlines which I'd rather not have.
0
 

Author Comment

by:purplesoup
ID: 41873810
Incidentally, adding the solution/project didn't work.
0
 

Author Comment

by:purplesoup
ID: 41873812
Just out of curiosity Ryan Chong are you not seeing this at all? If you just open an aspx page that references say Session it resolves it ok?
0
 

Accepted Solution

by:
purplesoup earned 0 total points
ID: 41873816
I just threw a class around the whole thing and it resolve it so

    
public class MyTest: UserControl
    { 
    protected void Page_Load(object sender, EventArgs e)
    {
        ClearMessage();
        LogMessage("page loaded");
        // LogMessage("accessing connection string");
        try {
            if (Session["ConnectionString"] == null) {

Open in new window


and now it can resolve Session... so that maybe the thing it wanted... weird!
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41873824
hmmm, no idea why VS behave like this, could it be a bug?

just wondering if you're using own compiled libraries in this project? just to make sure all your References are up-to-date.
0
 

Author Closing Comment

by:purplesoup
ID: 41880270
Adding the class fixed it
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question