Sunday, July 10, 2005

System.Web.HttpException: External component has thrown an exception

[This was originally posted at]

As far as debugging difficulty goes, anything that you can reproduce and step through with the debugger is likely simple. Sometimes you'll get an error that occurs before the codebehind is even hit, and you therefore can't debug it like "normal". One such error is: "System.Web.HttpException: External component has thrown an exception."

Web pages integrate both the aspx and codebehind pages. What may be happening is that some control in the html of the aspx page has an onserver attribute that references a non-existent server event. For example, you may have copied from a similar page that had a LinkButton with attribute onserverclick="AddLink_Click". The WebForm expects an "AddLink_Click" method in the codebehind. The original page may have had this method, but perhaps the target page does not. Therefore when you try to load the page, it can't "merge" the aspx and codebehind correctly and therefore crashes before even going to a breakpoint in the CodeBehind's Page_Load.

The solution (in this case) is to ensure that any attributes set in the aspx page are consistent with the codebehind.

No comments:

Post a Comment