ASP.NET 1.1 to ASP.NET 2.0 Migration #4
This problem does not applies to every situation. I faced this issue earlier today as I was migrating some codes from .NET 1.0 (back in Visual Studio .NET 2002 days) into ASP.NET 2.0.
The problem is most developers who moved into the .NET 1.0 platform came from VB6 background. So most of them will just create public variable declarations instead of having properties. Probably property was something new to everyone back then and not everyone followed best practices.
Example,
public class WebForm
{
public SomeClass a;
protected System.Web.UI.WebControls.TextBox txtUserName;
}
But when you tried to migrate that code above into ASP.NET 2.0, you will need to add partial keyword into that class. Then you need to comment out that 2 declarations as it is already been generated behind the scene.
Just say somewhere below this class, it will perform some calculation that will need to use a.
When you compile it, you will get this error "... inaccessible due to its protection level"
So what is the problem? It is definitely related to your access modifiers. But where. I checked almost everywhere and it looked okay.
Why this problem existed?
(Correct me if I am wrong)
When you place a partial class, it will generates the declarations behind the scene for you. Like this:
protected SomeClass a;
protected System.Web.UI.WebControls.TextBox txtUserName;
If you notice, a is not longer under public but protected.
In order to get it working, just create a public property like this:
public SomeClass A
{
get { return a; }
}
Then use A instead of a.
Hope it helps. But I am not sure this applies to every situation.