By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

Base page error at design time

P: n/a
I have .aspx code-behinds that inherit from the class below. The code runs
just fine, but the form designer bombs at design time when trying to view
the .aspx page in VS.NET 2003. If I comment out the single line of code
below, then there is no error. I posted the error message below - it
implies that this code is being run at design time, but it bombs due to the
fact that it isn't run time. Is there a line of code I could add to only
allow the code below to execute at run-time instead of design time?

Thanks,
Mark

public class MyBase: System.Web.UI.Page
{
public MyBase()
{
//This is the line that bombs. If it's commented out, the design time
viewer works fine.
System.Security.Principal.IIdentity ii = User.Identity;
//The some other code that does something with this identity.
}
}

**** THE ERROR ***

The file could not be loaded into the Web Forms designer. Please correct
the following error and then try loading it again:
An exception occurred while trying to create an instance of foo.bar. The
exception was "Object reference not set to an instance of an object.".
Make sure all of the classes used in the page are built or referenced in the
project.
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The code below appears to have solved my problem:

if (HttpContext.Current != null)
{
//This code bombs if it's not in the IF statement during design time - not
run time.
//I believe this is because pages inherit from it, and therefore it has to
create
//an instance of the object at design time. Since there is no "user" at
runtime,
//it bombs.
System.Security.Principal.IIdentity ii = User.Identity;
_strUser = ii.Name;
}

Mark

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eg**************@TK2MSFTNGP11.phx.gbl...
I have .aspx code-behinds that inherit from the class below. The code runs just fine, but the form designer bombs at design time when trying to view
the .aspx page in VS.NET 2003. If I comment out the single line of code
below, then there is no error. I posted the error message below - it
implies that this code is being run at design time, but it bombs due to the fact that it isn't run time. Is there a line of code I could add to only
allow the code below to execute at run-time instead of design time?

Thanks,
Mark

public class MyBase: System.Web.UI.Page
{
public MyBase()
{
//This is the line that bombs. If it's commented out, the design time
viewer works fine.
System.Security.Principal.IIdentity ii = User.Identity;
//The some other code that does something with this identity.
}
}

**** THE ERROR ***

The file could not be loaded into the Web Forms designer. Please correct
the following error and then try loading it again:
An exception occurred while trying to create an instance of foo.bar. The
exception was "Object reference not set to an instance of an object.".
Make sure all of the classes used in the page are built or referenced in the project.

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.