error BC30451: 'xxxx' is not declared.  It may be inaccessible due to its protection level

Christian de Bellefeuille
Christian de Bellefeuille used Ask the Experts™
I've converted an app from a previous version of VS and i'm getting tons of errors like this:
"error BC30451: 'xxxx' is not declared.  It may be inaccessible due to its protection level"

This code is inside a "ContentPlaceHolder" because this page is using a master file.
Here's a sample of code saying that UserListGrid is not declared.
(in ListUser.aspx)
<asp:Content ID="Content2" ContentPlaceHolderID="Contenu" Runat="Server">
<div id="contenu">
    <table bgcolor="#000000" border="0" width=100% cellspacing=0 cellpadding=0>
    <tr height="25"><td valign="middle">
    <div style="font-weight:bold; font-size:x-large; color:#FFFFFF;margin:5px 0 5px 0; text-align:center">
        <asp:Label ID="UserList" runat="server" Text="LISTE DES USAGERS" meta:resourcekey="TitleGridUserList"></asp:Label>
    <asp:GridView ID="UserListGrid" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
        BorderWidth="1px" CellPadding="4" DataSourceID="dsUserList" ForeColor="Black"
        GridLines="Vertical" width=100% DataKeyNames="UserName,UserId" 
        OnSelectedIndexChanged="SelectedUser" meta:resourcekey="GridUserList">

Open in new window

(in ListUser.aspx.vb)
Public Sub SelectedUser(ByVal sender As Object, ByVal e As System.EventArgs)
        ' *****************************************************************************
        ' Sub SelectedUser
        ' When an administrator select a user in the Users List, it trigger this function.
        ' It will fill the Drop Down List containing Roles properly by showing only Roles
        ' that this user doesn't yet.
        ' *****************************************************************************
        Dim sID, sUser As String

        If UserListGrid.SelectedRow IsNot Nothing Then
                sUser = UserListGrid.SelectedRow.Cells(IDX_COL_USERNAME).Text       ' Get the UserName for the selected user
                sID = UserListGrid.SelectedDataKey.Values(1).ToString()             ' Get the UserID for the selected user

                ' If there's a valid Guid, we modify the query to refresh the Drop Down List
                If sID <> "" Then
                    dsNewRole.SelectCommand = "SELECT * FROM vw_aspnet_Roles WHERE RoleId not In (SELECT RoleId FROM vw_aspnet_UsersInRoles WHERE UserId = '" & sID & "')"
                End If
            Catch ex As Exception
                ' Should place error trapping code here
            End Try

        End If
    End Sub

Open in new window

Thanks for your help
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Miguel OzSenior Software Engineer
Top Expert 2009

Please post your all master page and content page.

I want to check if:
1) Your code has a proper construct, like:
2) If your code has name collissions, meaning fileds named as  your gridview id, etc.

Note: if you can tell us form which version you convert your code from.
Most Valuable Expert 2012
Top Expert 2014
From what version to what? VS2010 introduced the .designer files for so that may be the reason behind these errors. How did you upgrade?


The code was originally written using VS2005.  

And i want to mention that the object UserListGrid is visible from the code behind of the content page!  I can type "Me." then intellisense show UserListGrid.  I also can see it from the top DropDown menu to set one of its event.

I cannot post the whole code here for privacy & security purpose.  

The whole master page is here:
<%@ Master Language="VB" CodeFile="Facilis.master.vb" Inherits="Facilis_secure_Facilis" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Facilis Conference Secured Zone</title>
    <link href="/Secure/css/screen.css" type="text/css" rel="stylesheet" />   

<form id="Facilis" runat="server">
    <div id="contenant">                  
        <table width=1000px bgcolor="black" style="color:White" height="70">
                <td><img src="/Secure/images/logo_facilis_mini.jpg" alt="Facilis" width="112" height="50" /></td>
                    <asp:LoginView ID="LoginView2" runat="server">
                            <asp:Login ID="Login1" runat="server" BorderStyle="None" BorderWidth="0px"  Font-Names="Verdana" Font-Size="10pt" Orientation="horizontal">
                                    <asp:TextBox ID="UserName" runat="server"  style="font-size:larger; color:white; padding-top:13px; text-align:center;background-image:url(/Secure/images/obj_username.jpg);z-index:2; width:188px; height:45px; background-repeat:no-repeat" BackColor="Transparent" BorderWidth="0px" Height="45px" Width="188px"></asp:TextBox>
                                    <asp:TextBox ID="Password" runat="server" TextMode="Password"  style="font-size:larger; color:white; padding-top:13px; text-align:center;background-image:url(/Secure/images/obj_password.jpg);z-index:2; width:188px; height:45px; background-repeat:no-repeat" BackColor="Transparent" BorderWidth="0px" ></asp:TextBox>
                                    <asp:Button ID="LoginButton" runat="server" CommandName="Login" style="vertical-align:top; margin-top:1px; background-image:url(/Secure/images/obj_login.jpg);z-index:2; width:188px; height:45px; background-repeat:no-repeat" BackColor="Transparent" BorderWidth="0px" ValidationGroup="ctl00$Login1" />
                                    <asp:CheckBox ID="RememberMe" runat="server" style="vertical-align:top" Text="Remember me next time." ForeColor="White" /><asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                            <asp:Label ID="CreerUsager" runat="server" Text="Vous n'avez pas de compte?"></asp:Label> <asp:LinkButton ID="btnCreateUser" runat="server" PostBackUrl="~/Secure/SecurityLevels/Anonymous/CreateUser.aspx">Créez votre compte.</asp:LinkButton>&nbsp;
                            Bonjour <asp:LoginName ID="LoginName1" runat="server" />! (<asp:LoginStatus ID="LoginStatus1" runat="server" />)
                            <asp:Menu ID="mnuTop" runat="server" Orientation="horizontal" DataSourceID="SiteMapDataSource1" BackColor="Black" BorderColor="Transparent" Font-Bold="True" Font-Names="Arial" Font-Overline="False" Font-Size="Medium" Font-Strikeout="False" Font-Underline="True" ForeColor="DarkKhaki" Height="50px" Width="100%" DynamicHorizontalOffset="10" >
                                <DynamicHoverStyle BackColor="#A39C6E" ForeColor="Black" Font-Size="Small" Font-Underline="True" />
                                <DynamicMenuStyle BackColor="#D3CC9E" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" HorizontalPadding="10px" VerticalPadding="10px" />
                                <DynamicMenuItemStyle Font-Size="Small" ForeColor="Black" />
                                <StaticHoverStyle ForeColor="#BBBF8C" />
        <asp:ContentPlaceHolder  ID="Contenu" runat="server" />

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />

Open in new window

The Master code behind is here (it contain nothing yet):
Partial Class Facilis_secure_Facilis
    Inherits System.Web.UI.MasterPage
End Class

Open in new window

Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.


@CodeCruiser: I've just tried to open the solution... but i did that long time ago and didn't checked at the result.  
Senior Software Engineer
Top Expert 2009
I think your issue is name clashing in your content page, notice that:
<asp:Content ID="Content2" ContentPlaceHolderID="Contenu" Runat="Server">
<div id="contenu">

You are using contenu as your id for both the div and ContentPlaceHolder. Replace these lines with:
<asp:Content ContentPlaceHolderID="Contenu" Runat="server">
<div id="contentmain">

Note: If this does not solve your problem I need the content page code. (I do not need the code behind but the class declaration, regarding markup, just leave the gridview and associated source on the markup code)


That's what i thought when i compiled that on VS2005, it worked perfectly.  On 2010, it fail.
Also, the DIV is not accessible as an object since it's not an ASP label with "Runat=Server" so the name shouldn't be a problem.

But i did the test... i've renamed "div" named "Contenu" for "Contenu2222" (no where in my code i try to access to this item, or do any FindControl in my code behind file).  Same result...

The part which intrigue me is the "may be inaccessible due to its protection level.".  I've not found any property giving me the opportunity to change the protection level in an asp:GridView (or any other asp object).  

My class is declared "Partial class TheNameOfTheClass" (as usual), it inherits from System.Web.UI.Page as it should.  My classes using the UserListGrid is "Public".  Do i have to switch that to private or anything else?


I'm using Visual Source Safe for my "versionning", and apparently this is causing the problem.  I'm not going to dig deeper to find what's the cause of the problem, but when i take my code out of the VSS, it work perfectly.

Since i'm the only person who work on that web site, i'll just keep my source out of VSS for the moment and keep backups of each versions manually.

Thanks for your help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial