Solved

Visual Studio Unable to resolve references in aspx file

Posted on 2016-11-03
12
22 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
  • 8
  • 4
12 Comments
 
LVL 51

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 51

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 51

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 51

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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