473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Programmatically retrieving ASPX Compilation Error details

I've Googled this for a while, to no avail. Hopefully someone can help me.
Maybe I'm using the wrong terminology.

Here's the scoop! Let's say I've got a simple *.ASPX page that has a syntax
error. For example, broken.aspx might only contain the following line of code:

<% Dim x as %>

When I visit this page from my Web browser, I see all the helpful ASP.NET
Server Error information, including:

Compilation Error
Compiler Error Message: BC30182: Type expected.
Source Error: Line 1: <% Dim x as %>
Source File: c:\inetpub\mysite\broken.aspx

This is great information; exactly what I need to troubleshoot the problem!
However on my site, I trap the Exception in my Global.asax.vb's
Application_Error handler so that I'm notified when an error occurs. Usually
I'm able to cull useful information from the Exception, but in the event of a
Compilation Error, here's all I can see:

System.Web.HttpException: External component has thrown an exception.
---> System.Web.HttpCompileException: External component has thrown an
exception.
at
System.Web.Compilation.BaseCompiler.ThrowIfCompile rErrors(CompilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String
sourceFile, String sourceString)
at System.Web.Compilation.BaseCompiler.GetCompiledTyp e()
at System.Web.UI.PageParser.CompileIntoType()
at System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation()
--- End of inner exception stack trace ---
at System.Web.UI.TemplateParser.GetParserCacheItemInt ernal(Boolean
fCreateIfNotFound)
at System.Web.UI.TemplateParser.GetParserCacheItemWit hNewConfigPath()
at System.Web.UI.TemplateParser.GetParserCacheItem()
at
System.Web.UI.TemplateControlParser.CompileAndGetP arserCacheItem(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.TemplateControlParser.GetCompiledIns tance(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageParser.GetCompiledPageInstanceIn ternal(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageHandlerFactory.GetHandler(HttpCo ntext context,
String requestType, String url, String path)
at System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, String path, String pathTranslated, Boolean useAppConfig)
at
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

The above is the result of "Server.GetLastError().ToString()" in my
Application_Error code.

So now I'm wondering, how can I *programmatically* learn the same
information shown in the first example output, when Application_Error event
handler executes?

I'm using the .NET Framework 1.1 SP 1.

Thanks for your help!
Nov 19 '05 #1
6 2851

"Plat" <Pl**@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
I've Googled this for a while, to no avail. Hopefully someone can help me.
Maybe I'm using the wrong terminology.

Here's the scoop! Let's say I've got a simple *.ASPX page that has a
syntax
error. For example, broken.aspx might only contain the following line of
code:

<% Dim x as %>


At the risk of being unhelpful...

Inline server-side script is allowed for backwards-compatability with asp,
but it should be avoided. This is just one of the many problems you will
have using inline VB in aspx.

Move all of your server-side code to code-behind classes and you will catch
compile errors at compile-time, where they belong. As well as better type
safety, easier debugging, intellisense, etc.

David
Nov 19 '05 #2
If you cast the Exception to an HttpCompileException (assuming the cast is
possible <g>), it should be possible to read the error details (including
line numbers) from the Errors collection of the CompilerResults object
exposed via the exception's Results property.

HTH,
Nicole

"Plat" <Pl**@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
I've Googled this for a while, to no avail. Hopefully someone can help me.
Maybe I'm using the wrong terminology.

Here's the scoop! Let's say I've got a simple *.ASPX page that has a
syntax
error. For example, broken.aspx might only contain the following line of
code:

<% Dim x as %>

When I visit this page from my Web browser, I see all the helpful ASP.NET
Server Error information, including:

Compilation Error
Compiler Error Message: BC30182: Type expected.
Source Error: Line 1: <% Dim x as %>
Source File: c:\inetpub\mysite\broken.aspx

This is great information; exactly what I need to troubleshoot the
problem!
However on my site, I trap the Exception in my Global.asax.vb's
Application_Error handler so that I'm notified when an error occurs.
Usually
I'm able to cull useful information from the Exception, but in the event
of a
Compilation Error, here's all I can see:

System.Web.HttpException: External component has thrown an exception.
---> System.Web.HttpCompileException: External component has thrown an
exception.
at
System.Web.Compilation.BaseCompiler.ThrowIfCompile rErrors(CompilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String
sourceFile, String sourceString)
at System.Web.Compilation.BaseCompiler.GetCompiledTyp e()
at System.Web.UI.PageParser.CompileIntoType()
at System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation()
--- End of inner exception stack trace ---
at System.Web.UI.TemplateParser.GetParserCacheItemInt ernal(Boolean
fCreateIfNotFound)
at System.Web.UI.TemplateParser.GetParserCacheItemWit hNewConfigPath()
at System.Web.UI.TemplateParser.GetParserCacheItem()
at
System.Web.UI.TemplateControlParser.CompileAndGetP arserCacheItem(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.TemplateControlParser.GetCompiledIns tance(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageParser.GetCompiledPageInstanceIn ternal(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageHandlerFactory.GetHandler(HttpCo ntext context,
String requestType, String url, String path)
at System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, String path, String pathTranslated, Boolean useAppConfig)
at
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

The above is the result of "Server.GetLastError().ToString()" in my
Application_Error code.

So now I'm wondering, how can I *programmatically* learn the same
information shown in the first example output, when Application_Error
event
handler executes?

I'm using the .NET Framework 1.1 SP 1.

Thanks for your help!


Nov 19 '05 #3
Very cool. You're my hero! :)

I was able to cast Server.GetLastError().GetBaseException() to a
System.Web.HttpCompileException in these cases, and pull the error details
from it, as you suggested (MSDN's doc examples were very helpful here).
Thanks for the help!

Out of curiosity, what's the reason why we see the "External component has
thrown an exception" error by default instead of something more detailed?

Thanks again.
"Nicole Calinoiu" wrote:
If you cast the Exception to an HttpCompileException (assuming the cast is
possible <g>), it should be possible to read the error details (including
line numbers) from the Errors collection of the CompilerResults object
exposed via the exception's Results property.

HTH,
Nicole

"Plat" <Pl**@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
I've Googled this for a while, to no avail. Hopefully someone can help me.
Maybe I'm using the wrong terminology.

Here's the scoop! Let's say I've got a simple *.ASPX page that has a
syntax
error. For example, broken.aspx might only contain the following line of
code:

<% Dim x as %>

When I visit this page from my Web browser, I see all the helpful ASP.NET
Server Error information, including:

Compilation Error
Compiler Error Message: BC30182: Type expected.
Source Error: Line 1: <% Dim x as %>
Source File: c:\inetpub\mysite\broken.aspx

This is great information; exactly what I need to troubleshoot the
problem!
However on my site, I trap the Exception in my Global.asax.vb's
Application_Error handler so that I'm notified when an error occurs.
Usually
I'm able to cull useful information from the Exception, but in the event
of a
Compilation Error, here's all I can see:

System.Web.HttpException: External component has thrown an exception.
---> System.Web.HttpCompileException: External component has thrown an
exception.
at
System.Web.Compilation.BaseCompiler.ThrowIfCompile rErrors(CompilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String
sourceFile, String sourceString)
at System.Web.Compilation.BaseCompiler.GetCompiledTyp e()
at System.Web.UI.PageParser.CompileIntoType()
at System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation()
--- End of inner exception stack trace ---
at System.Web.UI.TemplateParser.GetParserCacheItemInt ernal(Boolean
fCreateIfNotFound)
at System.Web.UI.TemplateParser.GetParserCacheItemWit hNewConfigPath()
at System.Web.UI.TemplateParser.GetParserCacheItem()
at
System.Web.UI.TemplateControlParser.CompileAndGetP arserCacheItem(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.TemplateControlParser.GetCompiledIns tance(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageParser.GetCompiledPageInstanceIn ternal(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageHandlerFactory.GetHandler(HttpCo ntext context,
String requestType, String url, String path)
at System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, String path, String pathTranslated, Boolean useAppConfig)
at
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

The above is the result of "Server.GetLastError().ToString()" in my
Application_Error code.

So now I'm wondering, how can I *programmatically* learn the same
information shown in the first example output, when Application_Error
event
handler executes?

I'm using the .NET Framework 1.1 SP 1.

Thanks for your help!


Nov 19 '05 #4
System.Web.HttpCompileException extends System.Web.HttpException, which
extends System.Runtime.InteropServices.ExternalException. Neither
HttpCompileException nor HttpException set their Message property. The only
constructor for HttpCompileException runs through the default constructors
for the two base types mentioned above, so the first time a Message setter
is hit is the default constructor for ExternalException, which sets it to
the text you see in the exception details.

HTH,
Nicole
"Plat" <Pl**@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
Very cool. You're my hero! :)

I was able to cast Server.GetLastError().GetBaseException() to a
System.Web.HttpCompileException in these cases, and pull the error details
from it, as you suggested (MSDN's doc examples were very helpful here).
Thanks for the help!

Out of curiosity, what's the reason why we see the "External component has
thrown an exception" error by default instead of something more detailed?

Thanks again.
"Nicole Calinoiu" wrote:
If you cast the Exception to an HttpCompileException (assuming the cast
is
possible <g>), it should be possible to read the error details (including
line numbers) from the Errors collection of the CompilerResults object
exposed via the exception's Results property.

HTH,
Nicole

"Plat" <Pl**@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
> I've Googled this for a while, to no avail. Hopefully someone can help
> me.
> Maybe I'm using the wrong terminology.
>
> Here's the scoop! Let's say I've got a simple *.ASPX page that has a
> syntax
> error. For example, broken.aspx might only contain the following line
> of
> code:
>
> <% Dim x as %>
>
> When I visit this page from my Web browser, I see all the helpful
> ASP.NET
> Server Error information, including:
>
> Compilation Error
> Compiler Error Message: BC30182: Type expected.
> Source Error: Line 1: <% Dim x as %>
> Source File: c:\inetpub\mysite\broken.aspx
>
> This is great information; exactly what I need to troubleshoot the
> problem!
> However on my site, I trap the Exception in my Global.asax.vb's
> Application_Error handler so that I'm notified when an error occurs.
> Usually
> I'm able to cull useful information from the Exception, but in the
> event
> of a
> Compilation Error, here's all I can see:
>
> System.Web.HttpException: External component has thrown an
> exception.
> ---> System.Web.HttpCompileException: External component has thrown an
> exception.
> at
> System.Web.Compilation.BaseCompiler.ThrowIfCompile rErrors(CompilerResults
> results, CodeDomProvider codeProvider, CodeCompileUnit sourceData,
> String
> sourceFile, String sourceString)
> at System.Web.Compilation.BaseCompiler.GetCompiledTyp e()
> at System.Web.UI.PageParser.CompileIntoType()
> at
> System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation()
> --- End of inner exception stack trace ---
> at System.Web.UI.TemplateParser.GetParserCacheItemInt ernal(Boolean
> fCreateIfNotFound)
> at System.Web.UI.TemplateParser.GetParserCacheItemWit hNewConfigPath()
> at System.Web.UI.TemplateParser.GetParserCacheItem()
> at
> System.Web.UI.TemplateControlParser.CompileAndGetP arserCacheItem(String
> virtualPath, String inputFile, HttpContext context)
> at System.Web.UI.TemplateControlParser.GetCompiledIns tance(String
> virtualPath, String inputFile, HttpContext context)
> at System.Web.UI.PageParser.GetCompiledPageInstanceIn ternal(String
> virtualPath, String inputFile, HttpContext context)
> at System.Web.UI.PageHandlerFactory.GetHandler(HttpCo ntext context,
> String requestType, String url, String path)
> at System.Web.HttpApplication.MapHttpHandler(HttpCont ext context,
> String
> requestType, String path, String pathTranslated, Boolean useAppConfig)
> at
> System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
> at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step,
> Boolean&
> completedSynchronously)
>
> The above is the result of "Server.GetLastError().ToString()" in my
> Application_Error code.
>
> So now I'm wondering, how can I *programmatically* learn the same
> information shown in the first example output, when Application_Error
> event
> handler executes?
>
> I'm using the .NET Framework 1.1 SP 1.
>
> Thanks for your help!


Nov 19 '05 #5
Just incase:
I found some help in this reference:

http://groups-beta.google.com/group/...899f56c254350f

*************************Here is what it
says*************************************

It's hard to know but your Stack Trace implies that something goes
wrong
in the dynamic process of creating assembly that represent the page
HTML
definition. What I suggest:
1) Delete the cache of your application from asp.net temporary files
directory located under C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322.
2) Double check with source safe for changes between the last deployed
version and the current one in the pages HTML.
HTH
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur

Thanks.

Nov 19 '05 #6

HttpCompileException ex = (HttpCompileException)
ctx.Server.GetLastError().GetBaseException();
string txtError = ex.GetHtmlErrorMessage().ToString();

vb net
Dim exh As HttpCompileException = Server.GetLastError.GetBaseException()
Dim txtError As String = exh.GetHtmlErrorMessage().ToString()

"Plat" escribió:
I've Googled this for a while, to no avail. Hopefully someone can help me.
Maybe I'm using the wrong terminology.

Here's the scoop! Let's say I've got a simple *.ASPX page that has a syntax
error. For example, broken.aspx might only contain the following line of code:

<% Dim x as %>

When I visit this page from my Web browser, I see all the helpful ASP.NET
Server Error information, including:

Compilation Error
Compiler Error Message: BC30182: Type expected.
Source Error: Line 1: <% Dim x as %>
Source File: c:\inetpub\mysite\broken.aspx

This is great information; exactly what I need to troubleshoot the problem!
However on my site, I trap the Exception in my Global.asax.vb's
Application_Error handler so that I'm notified when an error occurs. Usually
I'm able to cull useful information from the Exception, but in the event of a
Compilation Error, here's all I can see:

System.Web.HttpException: External component has thrown an exception.
---> System.Web.HttpCompileException: External component has thrown an
exception.
at
System.Web.Compilation.BaseCompiler.ThrowIfCompile rErrors(CompilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String
sourceFile, String sourceString)
at System.Web.Compilation.BaseCompiler.GetCompiledTyp e()
at System.Web.UI.PageParser.CompileIntoType()
at System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation()
--- End of inner exception stack trace ---
at System.Web.UI.TemplateParser.GetParserCacheItemInt ernal(Boolean
fCreateIfNotFound)
at System.Web.UI.TemplateParser.GetParserCacheItemWit hNewConfigPath()
at System.Web.UI.TemplateParser.GetParserCacheItem()
at
System.Web.UI.TemplateControlParser.CompileAndGetP arserCacheItem(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.TemplateControlParser.GetCompiledIns tance(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageParser.GetCompiledPageInstanceIn ternal(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageHandlerFactory.GetHandler(HttpCo ntext context,
String requestType, String url, String path)
at System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, String path, String pathTranslated, Boolean useAppConfig)
at
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

The above is the result of "Server.GetLastError().ToString()" in my
Application_Error code.

So now I'm wondering, how can I *programmatically* learn the same
information shown in the first example output, when Application_Error event
handler executes?

I'm using the .NET Framework 1.1 SP 1.

Thanks for your help!

Mar 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jim Hansen | last post by:
I re-installed Framework and now I am getting this error ClassBrowser. Most other page work just fine. Additionally, the debugger will not start from Visual Studio 2003.. Compilation Error...
2
by: Carpe Diem | last post by:
Hello all. My host is experiencing some troubles and I think you'll answer me before they can. After I uploaded a slightly changed JScript.NET .aspx page (the contents are not important, could be...
7
by: Holger (David) Wagner | last post by:
Hi Group, I've searched the Web for precompilers that compile ASPX/ASCX pages just like it can be done with JSPs, but so far, I've only found approaches targetted at increasing the performance....
18
by: Praveen Ramesh | last post by:
Hi, Is there any way to add the @Assembly reference to the aspx files programmatically from inside a custom control (when it gets dropped on to the page from the toolbox)? I have a custom...
10
by: bienwell | last post by:
Hi, I have a question about file included in ASP.NET. I have a file that includes all the Sub functions (e.g FileFunct.vb). One of the functions in this file is : Sub TestFunct(ByVal...
0
by: Stimp | last post by:
I've created an aspx page called HistoryManage.aspx. The page works fine on my local machine but when I load it off the web I get the following strange error... Compilation Error...
0
by: Ramesh2006 | last post by:
Hi, The following error occurred when i programmatically compile another project from my present project. The Error: error CS0234:The type or namespace name 'Windows' does not exist in the...
7
by: rfinch | last post by:
Very new to this but using the MS working with dynamics CRM 3.0 book to run web application to retrieve lead records from CRM 3.0. Have followed the book instructions on page 380-382. But am...
13
by: MCPD | last post by:
hello i have an aspx page that write in javascript its too small file when i upload it to my website i got an error Server Error in '/' Application....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.