Solved

Visual Studio Unable to resolve references in aspx file

Posted on 2016-11-03
12
23 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 52

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 52

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
DevOps Toolchain Recommendations

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

 

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 52

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 52

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

738 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