Errors: Type Abstract and Key in appSettings does not exist
I ran into a problem yesterday where I have a base class from which all my aspx pages inherit from. When I swithed to design view it gave me the following error: The file could not be loaded into the Web Forms Designer .... Type Abstract.
I love google groups and I got the answer there. “The reason for this is that VS doesn't support design view for controls/forms that inherit from abstract classes.
When you open the derived page in the designer, VS.NET needs to create an instance of the Page's class. For windows forms, it creates the class to display what the form looks like. For web forms it calls methods to get what the form looks like. If the class is abstract the designer does not know how to fill in your abstract methods.
A common work around is to make your class abstract for release builds, but not for debug builds, then when you are designing your app, make sure it is a debug build.
What you can do:
#if(DEBUG)
public class RolesBase : System.Web.UI.Page
#else
public abstract class RolesBase : System.Web.UI.Page
#endif
{
#if(DEBUG)
public virtual void method1()
{
throw new NotImplementedException();
}
#else
public abstract void method1()
#endif
}
Not the cleanest but it works, during Release builds you will get compile
errors if you do not implement an abstract method, during debug builds you
will get run time errors.“
Ok, that error sorted. Now I am getting another one that haven't found a solution to yet. I also posted it on SADev, but no response yet :(
Basically this base class checks the users permissions on the page by calling a method that resides in the data access layer. This method uses a connection string from web.config.
When I run it, all is fine, now the problem comes in again when I want to switch to design view on one of the derived pages. I receive the following error: "An exception occurred while trying to create an instance of luxury.cRolesBase. The exception was: The key 'Main.ConnectionString' does not exist in the appSettings configuration section."
I copied all the functionality, including a connection string into the base class, which means it doesn't even access the web.config file anymore, but I still get the same error...
I also tried to move the call to the method into the Form_Load event, but it didn't help. At this stage I don't know where to turn to, but will update this post if/when I find a solution :)