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! | | | | re: Programmatically retrieving ASPX Compilation Error details
"Plat" <Plat@discussions.microsoft.com> wrote in message
news:C7DB2043-0892-469D-8945-B3FC6AC4508E@microsoft.com...[color=blue]
> 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 %>
>[/color]
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 | | | | re: Programmatically retrieving ASPX Compilation Error details
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" <Plat@discussions.microsoft.com> wrote in message
news:C7DB2043-0892-469D-8945-B3FC6AC4508E@microsoft.com...[color=blue]
> 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![/color] | | | | re: Programmatically retrieving ASPX Compilation Error details
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:
[color=blue]
> 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" <Plat@discussions.microsoft.com> wrote in message
> news:C7DB2043-0892-469D-8945-B3FC6AC4508E@microsoft.com...[color=green]
> > 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![/color]
>
>
>
>[/color] | | | | re: Programmatically retrieving ASPX Compilation Error details
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" <Plat@discussions.microsoft.com> wrote in message
news:763EC775-D392-4FCE-8E15-3D22D34A091A@microsoft.com...[color=blue]
> 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:
>[color=green]
>> 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" <Plat@discussions.microsoft.com> wrote in message
>> news:C7DB2043-0892-469D-8945-B3FC6AC4508E@microsoft.com...[color=darkred]
>> > 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![/color]
>>
>>
>>
>>[/color][/color] | | | | re: Programmatically retrieving ASPX Compilation Error details
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. | | | | re: Programmatically retrieving ASPX Compilation Error details
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ó:
[color=blue]
> 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![/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|