473,372 Members | 1,070 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,372 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 2856

"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....
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.