|
 |
aspdotnet_website_programming thread: Newbie debugging help
Message #1 by "John Dillon" <john@m...> on Mon, 21 Oct 2002 22:49:53 +0100
|
|
Hi All
Appologies for the dimness of my Q but I am new to .NET debugging.
Anyway I have the following code structure written in notepad and I am
getting error messages but dont know how or where to find out more / debug
them.
My code is trying to load a set of default page attributes from a
PageSetting Class. The data is transferred into the context object in the
global.asax event Application_BeginRequest. This is where I think my
problems begin as I get a fatal error as soon as I try to load any of the
information. My problem is that I dont know what to do with the error
message or where its pointing me. I understand what type of error it is but
not which piece of code its referring to.
ALSO How do I use the debugger?
So far I have set debug and trace values in web.config to true, and I have
compiled it with these values set (supposedly). BUT when I come to open the
debugger and set breakpoints it always says the breakpoint will not be hit
as no symbols have been loaded for this document!! - How do I load symbols?
I thought you did this by setting /d:TRACE /d:DEBUG=TRUE in your compliation
statement?
Code to follow...............
*-- ERROR
MESSAGE --------------------------------------------------------------------
-----------*
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
TemplateApp.Templates.PageDetails..ctor(Int32 pageid, Int32 siteid)
TemplateApp.Global.Application_BeginRequest(Object sender, EventArgs e)
System.Web.SyncEventExecutionStep.Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87
*----
GLOBAL.ASCX.CS--------------------------------------------------------------
------------*
protected void Application_BeginRequest(Object sender, EventArgs e)
{
//Temp settings
int pageid = 0;
int siteid = 0;
pageid = Int32.Parse("1");
siteid = Int32.Parse("1");
Context.Items.Add("PageDetails", new PageDetails(pageid, siteid));
}
*-----PAGESETTING.CS--------------------------------------------------------
------------------*
using System;
using System.Configuration;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace TemplateApp.Templates {
//*********************************************************************
//
// NavBarSettings Class
//
// Individual details for a specific Navbar (1,2 or 3)
//
//*********************************************************************
public class NavBarSettings {
public int PageID;
public int SiteID;
public int NavBarType;
public String NavLinkName;
public String NavLinkURL;
public int NavLinkOrder;
public int ParentID;
}
//*********************************************************************
//
// PageDetails Class
//
// This class encapsulates all of the settings for the Page, as well
// as the configuration settings required to execute the current tab
// view within the page.
//
//*********************************************************************
public class PageDetails {
public int PageID;
public int SiteID;
public String SiteAlias;
public String Title;
public String Scripts;
public String Styles;
public String Metas;
public String BodyOnload;
public int ParentID;
public String LeftNavModules;
public String MainContentModules;
// Create array to hold all navlinks used on this page
public ArrayList NavLinks = new ArrayList();
//*********************************************************************
//
// pageSettings Constructor
//
// The pageSettings Constructor encapsulates all of the logic
// necessary to obtain configuration settings necessary to render
// a page Tab view for a given request.
//
// These page Settings are stored within a SQL database, and are
// fetched below by calling the "GetpageSettings" stored procedure.
// This stored procedure returns values as SPROC output parameters,
// and using three result sets.
//
//*********************************************************************
public PageDetails(int pageid, int siteid) {
// Create Instance of Connection and Command Object
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("GetPageSettings", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterPageID = new SqlParameter("@PageID", SqlDbType.Int,
4);
parameterPageID.Value = PageID;
myCommand.Parameters.Add(parameterPageID);
SqlParameter parameterSiteID = new SqlParameter("@SiteID", SqlDbType.Int,
4);
parameterSiteID.Value = SiteID;
myCommand.Parameters.Add(parameterSiteID);
// Add out parameters to Sproc
SqlParameter parameterSiteAlias = new SqlParameter("@SiteAlias",
SqlDbType.NVarChar, 50);
parameterSiteAlias.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterSiteAlias);
SqlParameter parameterTitle = new SqlParameter("@Title", SqlDbType.NVarChar,
128);
parameterTitle.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterTitle);
SqlParameter parameterScripts = new SqlParameter("@Scripts",
SqlDbType.NVarChar, 150);
parameterScripts.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterScripts);
SqlParameter parameterStyles = new SqlParameter("@Styles",
SqlDbType.NVarChar, 150);
parameterStyles.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterStyles);
SqlParameter parameterMetas = new SqlParameter("@Metas", SqlDbType.NVarChar,
100);
parameterMetas.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterMetas);
SqlParameter parameterBodyOnload = new SqlParameter("@BodyOnload",
SqlDbType.NVarChar, 100);
parameterBodyOnload.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterBodyOnload);
SqlParameter parameterParentID = new SqlParameter("@ParentID",
SqlDbType.Int, 4);
parameterParentID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterParentID);
SqlParameter parameterLeftNavModules = new SqlParameter("@LeftNavModules",
SqlDbType.NVarChar, 200);
parameterLeftNavModules.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterLeftNavModules);
SqlParameter parameterContentModules = new SqlParameter("@ContentModules",
SqlDbType.NVarChar, 200);
parameterContentModules.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterContentModules);
SqlParameter parameterNavLinkName = new SqlParameter("@NavLinkName",
SqlDbType.NVarChar, 200);
parameterNavLinkName.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterNavLinkName);
SqlParameter parameterNavLinkURL = new SqlParameter("@NavLinkURL",
SqlDbType.NVarChar, 200);
parameterNavLinkURL.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterNavLinkURL);
SqlParameter parameterNavLinkOrder = new SqlParameter("@NavLinkOrder",
SqlDbType.Int, 4);
parameterNavLinkOrder.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterNavLinkOrder);
SqlParameter parameterNavBarType = new SqlParameter("@NavBarType",
SqlDbType.Int, 200);
parameterNavBarType.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterNavBarType);
// Open the database connection and execute the command
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader();
// Get all navlinks where SiteID=valid
while(result.Read()) {
// Create new NavBarSettings class based on which navlinks can be added
NavBarSettings navbarSettings = new NavBarSettings();
navbarSettings.PageID = PageID;
navbarSettings.SiteID = SiteID;
navbarSettings.NavBarType = (int) result["NavBarType"];
navbarSettings.NavLinkName = (String) result["NavLinkName"];
navbarSettings.NavLinkURL = (String) result["NavLinkURL"];
navbarSettings.NavLinkOrder = (int) result["NavLinkOrder"];
navbarSettings.ParentID = (int) result["ParentID"];
this.NavLinks.Add(navbarSettings);
}
// Now read Site out params
result.NextResult();
this.SiteID = SiteID;
this.PageID = PageID;
this.Title = (String) parameterTitle.Value;
this.Scripts = (String) parameterScripts.Value;
this.Styles = (String) parameterStyles.Value;
this.Metas = (String) parameterMetas.Value;
this.BodyOnload = (String) parameterBodyOnload.Value;
this.ParentID = (int) parameterParentID.Value;
this.LeftNavModules = (String) parameterLeftNavModules.Value;
this.MainContentModules = (String) parameterContentModules.Value;
myConnection.Close();
}
}
}
*---------------------------------------------------------------------------
-------------------------*
Many thanks for any help which is given
John
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.380 / Virus Database: 213 - Release Date: 24/07/2002
Message #2 by "Mike Gale" <info@d...> on Tue, 22 Oct 2002 11:56:42 +1300
|
|
John Dillon wrote:
> Apologies for the dimness of my Q but I am new to .NET debugging.
> Anyway I have the following code structure written in notepad and I am
> getting error messages but don't know how or where to find out more /
> debug them.
>
> My code is trying to load a set of default page attributes from a
> PageSetting Class. The data is transferred into the context object in
> the global.asax event Application_BeginRequest. This is where I think
> my problems begin as I get a fatal error as soon as I try to load any
> of the information. My problem is that I don't know what to do with
> the error message or where its pointing me. I understand what type of
> error it is but not which piece of code its referring to.
>
> ALSO How do I use the debugger?
> So far I have set debug and trace values in web.config to true, and I
> have compiled it with these values set (supposedly). BUT when I come
> to open the debugger and set breakpoints it always says the
> breakpoint will not be hit as no symbols have been loaded for this
> document!! - How do I load symbols? I thought you did this by setting
> /d:TRACE /d:DEBUG=TRUE in your compilation statement?
Hi John,
A few notes that may be of some use.
1) I tried out five or so .NET editing environments about a year ago.
My conclusion was that a good IDE (i.e. a good editing environment) was
very important. .NET is huge and without code completion your job gets
very hard. I'm using Visual Studio and have got so used to it I'd hate
to code without it (despite it's bugs of which there are a few!). If I
were you I'd check for some editing support. If the budget is low check
the free SharpDevelop product (on SourceForge). This has (I believe)
advanced since the beginning of the year and has features which are very
like Visual Studio. There is also the free WebMatrix from Microsoft
(I've not tried it). (VS handles all the plumbing for debugging etc
behind the scenes.)
2) Compiling can be done for release or for debugging. I've used VS so
long I've forgotten how you set this up manually. The essential issue
is, a debug compile produces a file with a pdb extension so you get
mycode.dll and mycode.pdb. If you haven't got these files there are no
"debug symbols" for you.
3) You can log exceptions in a lot of detail. This is very useful
(once you figure out what it means) in pinpointing problem areas. I'd
suggest logging to file and potentially to email.
4) There are good books on .NET. I personally often refer to
"Professional ASP.NET" even though mine is written for a pre-release
version. It has a brief section on debugging with the SDK debugger
saying "it is far above anything we've seen in the ASP world".
If you edit by hand I wish you good luck. I've found that there is so
much to learn in the framework that I can't afford distractions. (Even
saying that the learning will take years in the best of circumstances.)
Mike Gale, Decision Engineering (NZ) Ltd.
Message #3 by Helen Warn <hwarn@s...> on Mon, 21 Oct 2002 16:26:39 -0700
|
|
You must also make sure that you have set your Web Application to use
Integrated Windows authentication in order to be able to debug your ASP.NET
project.
hth
Helen
> -----Original Message-----
> From: Mike Gale [mailto:info@d...]
> Sent: Monday, October 21, 2002 3:57 PM
> To: Website Programming with ASP.NET
> Subject: [aspdotnet_website_programming] RE: Newbie debugging help
>
>
> John Dillon wrote:
> > Apologies for the dimness of my Q but I am new to .NET debugging.
> > Anyway I have the following code structure written in
> notepad and I am
> > getting error messages but don't know how or where to find
> out more /
> > debug them.
> >
> > My code is trying to load a set of default page attributes from a
> > PageSetting Class. The data is transferred into the context
> object in
> > the global.asax event Application_BeginRequest. This is
> where I think
> > my problems begin as I get a fatal error as soon as I try
> to load any
> > of the information. My problem is that I don't know what to do with
> > the error message or where its pointing me. I understand
> what type of
> > error it is but not which piece of code its referring to.
> >
> > ALSO How do I use the debugger?
> > So far I have set debug and trace values in web.config to
> true, and I
> > have compiled it with these values set (supposedly). BUT when I come
> > to open the debugger and set breakpoints it always says the
> > breakpoint will not be hit as no symbols have been loaded for this
> > document!! - How do I load symbols? I thought you did this
> by setting
> > /d:TRACE /d:DEBUG=TRUE in your compilation statement?
>
> Hi John,
>
> A few notes that may be of some use.
>
> 1) I tried out five or so .NET editing environments about a year ago.
> My conclusion was that a good IDE (i.e. a good editing
> environment) was
> very important. .NET is huge and without code completion
> your job gets
> very hard. I'm using Visual Studio and have got so used to
> it I'd hate
> to code without it (despite it's bugs of which there are a
> few!). If I
> were you I'd check for some editing support. If the budget
> is low check
> the free SharpDevelop product (on SourceForge). This has (I believe)
> advanced since the beginning of the year and has features
> which are very
> like Visual Studio. There is also the free WebMatrix from Microsoft
> (I've not tried it). (VS handles all the plumbing for debugging etc
> behind the scenes.)
>
> 2) Compiling can be done for release or for debugging. I've
> used VS so
> long I've forgotten how you set this up manually. The essential issue
> is, a debug compile produces a file with a pdb extension so you get
> mycode.dll and mycode.pdb. If you haven't got these files
> there are no
> "debug symbols" for you.
>
> 3) You can log exceptions in a lot of detail. This is very useful
> (once you figure out what it means) in pinpointing problem areas. I'd
> suggest logging to file and potentially to email.
>
> 4) There are good books on .NET. I personally often refer to
> "Professional ASP.NET" even though mine is written for a pre-release
> version. It has a brief section on debugging with the SDK debugger
> saying "it is far above anything we've seen in the ASP world".
>
> If you edit by hand I wish you good luck. I've found that there is so
> much to learn in the framework that I can't afford
> distractions. (Even
> saying that the learning will take years in the best of
> circumstances.)
>
> Mike Gale, Decision Engineering (NZ) Ltd.
>
>
Message #4 by "Charles Walsek" <cwalsek@w...> on Mon, 21 Oct 2002 19:42:40 -0400
|
|
Do you know to recover from this dialog box while debugging:
Microsoft Development Environment- Error while trying to run project:
Unable to start debugging on the web server. System call failed. Would you
like to disable future attempts to debug ASP.NET pages for this project?
I can debug other projects, but no longer ThePhile. I was working on
incorporating the Polls Module into the project when I encountered the
error. Ive tried rebooting and rebuilding, w/o success. All I can come up
with now is to begin another solution and bring the code in, one project at
a time. Seems like there ought to be an easier way. Comments anyone?
----- Original Message -----
From: "Mike Gale" <info@d...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Monday, October 21, 2002 6:56 PM
Subject: [aspdotnet_website_programming] RE: Newbie debugging help
> John Dillon wrote:
> > Apologies for the dimness of my Q but I am new to .NET debugging.
> > Anyway I have the following code structure written in notepad and I am
> > getting error messages but don't know how or where to find out more /
> > debug them.
> >
> > My code is trying to load a set of default page attributes from a
> > PageSetting Class. The data is transferred into the context object in
> > the global.asax event Application_BeginRequest. This is where I think
> > my problems begin as I get a fatal error as soon as I try to load any
> > of the information. My problem is that I don't know what to do with
> > the error message or where its pointing me. I understand what type of
> > error it is but not which piece of code its referring to.
> >
> > ALSO How do I use the debugger?
> > So far I have set debug and trace values in web.config to true, and I
> > have compiled it with these values set (supposedly). BUT when I come
> > to open the debugger and set breakpoints it always says the
> > breakpoint will not be hit as no symbols have been loaded for this
> > document!! - How do I load symbols? I thought you did this by setting
> > /d:TRACE /d:DEBUG=TRUE in your compilation statement?
>
> Hi John,
>
> A few notes that may be of some use.
>
> 1) I tried out five or so .NET editing environments about a year ago.
> My conclusion was that a good IDE (i.e. a good editing environment) was
> very important. .NET is huge and without code completion your job gets
> very hard. I'm using Visual Studio and have got so used to it I'd hate
> to code without it (despite it's bugs of which there are a few!). If I
> were you I'd check for some editing support. If the budget is low check
> the free SharpDevelop product (on SourceForge). This has (I believe)
> advanced since the beginning of the year and has features which are very
> like Visual Studio. There is also the free WebMatrix from Microsoft
> (I've not tried it). (VS handles all the plumbing for debugging etc
> behind the scenes.)
>
> 2) Compiling can be done for release or for debugging. I've used VS so
> long I've forgotten how you set this up manually. The essential issue
> is, a debug compile produces a file with a pdb extension so you get
> mycode.dll and mycode.pdb. If you haven't got these files there are no
> "debug symbols" for you.
>
> 3) You can log exceptions in a lot of detail. This is very useful
> (once you figure out what it means) in pinpointing problem areas. I'd
> suggest logging to file and potentially to email.
>
> 4) There are good books on .NET. I personally often refer to
> "Professional ASP.NET" even though mine is written for a pre-release
> version. It has a brief section on debugging with the SDK debugger
> saying "it is far above anything we've seen in the ASP world".
>
> If you edit by hand I wish you good luck. I've found that there is so
> much to learn in the framework that I can't afford distractions. (Even
> saying that the learning will take years in the best of circumstances.)
>
> Mike Gale, Decision Engineering (NZ) Ltd.
>
>
Message #5 by "Mike Gale" <info@d...> on Tue, 22 Oct 2002 13:00:40 +1300
|
|
Charles Walsek wrote:
> Do you know to recover from this dialog box while debugging:
>
> Microsoft Development Environment- Error while trying to run project:
> Unable to start debugging on the web server. System call failed.
> Would you like to disable future attempts to debug ASP.NET pages for
> this project?
>
> I can debug other projects, but no longer ThePhile. I was working on
> incorporating the Polls Module into the project when I encountered the
> error. I've tried rebooting and rebuilding, w/o success. All I can
> come up with now is to begin another solution and bring the code in,
> one project at a time. Seems like there ought to be an easier way.
> Comments anyone?
I've not had this exact message but I have had VS give me BSE's (Blue
Screen Events). This appears to be associated with compiling in debug
mode.
A cycle to identify the cause takes longer than the fix so I now simply
take both actions I've identified in the past.
1) Delete all dll's and pdb's. After doing that check that they are
actually gone. I had one that couldn't be deleted, but it could be
renamed and moved so I did that. (If you have external dll's in bin
leave these!)
2) Compile each component project starting at those with no
interproject dependencies (In thePhile Core first) and work towards
those that have dependencies (in thePhile the ASP.NET project).
This fixes my problems.
I've also noted that sometimes a wait of a few minutes does the trick.
(Does not fix "BSE faults".)
My sense is that VS struggles when it has a lot of projects (maybe
exacerbated by debug mode) to deal with. If you can drop projects from
a solution after those projects have gone to release things speed up.
Mike Gale, Decision Engineering (NZ) Ltd.
Message #6 by "Charles Walsek" <cwalsek@w...> on Tue, 22 Oct 2002 18:22:43 -0400
|
|
Thanks Mike. I deleted all dll's & pdb's. That did not work, else it was
not enough. I next started removing from the solution recent pages. That
seems to do the trick. Then I slowly added the pages back, checking the
debug capability with each new page. I'm OK now.
FYI: The MSDN knowledge base contained an entry for this condition. It's
solution was to reset IIS with iisreset.exe from the dos prompt. That did
not do a thing for me.
.NET is nice technology, but VS.NET is buggy. Maybe next release will
stablize some.
----- Original Message -----
From: "Mike Gale" <info@d...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Monday, October 21, 2002 8:00 PM
Subject: [aspdotnet_website_programming] RE: Newbie debugging help
> Charles Walsek wrote:
> > Do you know to recover from this dialog box while debugging:
> >
> > Microsoft Development Environment- Error while trying to run project:
> > Unable to start debugging on the web server. System call failed.
> > Would you like to disable future attempts to debug ASP.NET pages for
> > this project?
> >
> > I can debug other projects, but no longer ThePhile. I was working on
> > incorporating the Polls Module into the project when I encountered the
> > error. I've tried rebooting and rebuilding, w/o success. All I can
> > come up with now is to begin another solution and bring the code in,
> > one project at a time. Seems like there ought to be an easier way.
> > Comments anyone?
>
> I've not had this exact message but I have had VS give me BSE's (Blue
> Screen Events). This appears to be associated with compiling in debug
> mode.
>
> A cycle to identify the cause takes longer than the fix so I now simply
> take both actions I've identified in the past.
>
> 1) Delete all dll's and pdb's. After doing that check that they are
> actually gone. I had one that couldn't be deleted, but it could be
> renamed and moved so I did that. (If you have external dll's in bin
> leave these!)
>
> 2) Compile each component project starting at those with no
> interproject dependencies (In thePhile Core first) and work towards
> those that have dependencies (in thePhile the ASP.NET project).
>
> This fixes my problems.
>
> I've also noted that sometimes a wait of a few minutes does the trick.
> (Does not fix "BSE faults".)
>
> My sense is that VS struggles when it has a lot of projects (maybe
> exacerbated by debug mode) to deal with. If you can drop projects from
> a solution after those projects have gone to release things speed up.
>
> Mike Gale, Decision Engineering (NZ) Ltd.
>
>
Message #7 by "Mike Gale" <info@d...> on Wed, 23 Oct 2002 11:51:14 +1300
|
|
Charles Walsek wrote:
> Thanks Mike. I deleted all dll's & pdb's. That did not work, else
> it was not enough. I next started removing from the solution recent
> pages. That seems to do the trick. Then I slowly added the pages
> back, checking the debug capability with each new page. I'm OK now.
...
>
> .NET is nice technology, but VS.NET is buggy. Maybe next release will
> stablize some.
Thanks Charles. Good to see the thorough professional approach working.
I'll include this to my arsenal.
I know some people are testing "Everett" at present. (Next version of
VS.) I've also heard that release is scheduled before year end, but I'll
only believe that if I see it.
Mike Gale, Decision Engineering (NZ) Ltd.
|
|
 |