Solved

Visual Studio Unable to resolve references in aspx file

Posted on 2016-11-03
12
21 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 50

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 50

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 50

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 50

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

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.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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