Solved

VS2005 VB.NET WEB - variables not declared that are.

Posted on 2007-03-23
5
513 Views
Last Modified: 2008-02-20
VS2005 SP1 VB.NET WEB Application

I have an application which is in devlopment and had no problem until today.  Suddenly variables that are clearlr declared are flagged  as not declared and I can no longer build the project. It appears ANY new code i add to the project sufferes this fate. So I will pick a simple example: In code behind I have.

    Protected Function LoadUsers(ByVal CaseID As String) As Boolean
        Dim strSelect As String = "SELECT USERNAME  FROM CASEUSERS WHERE (CaseID =" & Trim(CaseID) & ") ORDER BY USERNAME ASC"
        With dsCaseU
            .SelectCommand = strSelect
            .DataBind()
        End With
        dListUsers.DataBind()
    End Function

In ASPX I have

    <asp:SqlDataSource ID="dsCaseU" runat="server" ConnectionString="<%$ ConnectionStrings:CMSConnectionString %>"
                SelectCommand="SELECT DISTINCT USERNAME  FROM CaseUsers   ORDER BY USERNAME ASC">
            </asp:SqlDataSource>  

And doing a solution build I get:

E:\CMS.NET\CMSCaseBlog.aspx.vb(63,0): error BC30451: Name 'dsCaseU' is not declared.
E:\CMS.NET\CMSCaseBlog.aspx.vb(67,0): error BC30451: Name 'dListUsers' is not declared.
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

Note these names are not highlighted in blue by intellisense.

Some background. The problem started this morning and I had the same as above except these variables WERE highlighted in blue in the code behind as not declared .

Out of frustration I de-installed VS2005 completely and re-installed it. I also upgraded to SP1. Now I get this result and still cannot move forward.

Am I missing somethning stupid?



0
Comment
Question by:rschnell11
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
ethoths earned 500 total points
ID: 18781652
Are you missing the partial class. Vb.Net 2.0 puts all the auto generated code in a seperate designer class.
0
 
LVL 27

Expert Comment

by:Sammy
ID: 18782020
check and see if any of these variables are commented out for debugging purposes
0
 

Author Comment

by:rschnell11
ID: 18782398
1. check and see if any of these variables are commented out for debugging purposes

It happens to all variables that are added now, this is not just a sample. Existing ones are Ok.  for example if I add the folloing to the end of the aspx and add another line to the vb code, now SQLdataSource1 is not declared. Any change results in variables in the code behind not declared.
CODE BEHIND  CHANGE
        dListUsers.DataBind()
        SqlDataSource1.DataBind()
:
ASPX CHANGE
              <asp:SqlDataSource ID="dsUsers" runat="server" ConnectionString="<%$ ConnectionStrings:CMSConnectionString %>"
                SelectCommand="SELECT USERNAME  FROM USERS ORDER BY USERNAME ASC">
            </asp:SqlDataSource>
           
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CMSConnectionString %>"
                SelectCommand="SELECT USERNAME  FROM USERS ORDER BY USERNAME ASC">
            </asp:SqlDataSource>
           
        </div>
    </form>
</body>
</html>


2. Mising partial class.
All the code is encompassed within the partial class
Partial Class AddNote
    Inherits System.Web.UI.Page
      .
      .
      .
End Class
0
 
LVL 27

Expert Comment

by:Sammy
ID: 18782494
can you check in IIS if your app is running under asp.net 2.0 and Not 1.1
0
 

Author Comment

by:rschnell11
ID: 18782605
Sorry I should have satid,its NET 2.0.
However, "ethoths" is correct. I just looked up the details oh how partial classes work. So realising the implications, I changed the name of the partial class to something I am absolutely sure is unique ... and now its all working. I still don't understand why it stopped working today as I only added the three or four lines of code and only to this class and it was just working before that. However, I guess if there is some other codebehind partilal class with a duplicate name, I understand now that there may well be a conflict, looking in the wrong aspx perhaps?

The main thing is that its working again. Thank you all.

So whilst I am not sure how the problem occured , partial class naming is the source of the problem.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 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