Solved

Visual Studio Unable to resolve references in aspx file

Posted on 2016-11-03
12
15 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 49

Expert Comment

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

Author Comment

by:purplesoup
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
Seems ok for me... what if you "Rebuild" (menu Build > Rebuild) your solution? will that red highlighting gone?
0
 

Author Comment

by:purplesoup
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
ok I'll see what happens - would just have been nice to open a file and have it work... :(
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:purplesoup
Comment Utility
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
Comment Utility
Incidentally, adding the solution/project didn't work.
0
 

Author Comment

by:purplesoup
Comment Utility
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
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
Adding the class fixed it
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now