|
|
|
|
|
|
|
|
|
|
|
|
|
|
Click Mice, Unclick Mice > Posts > Debugging obtuse SharePoint errors
|
|
8/13/2007
- An unknown error has occurred.
- An unexpected error has occurred.
If you have ever done any custom web parts or other custom code in a SharePoint installation you have probably seen this message. Lately I have also found this set of steps useful for tracking down other odd things like the GroupBoard Workspace issue. There are lots of reasons this can happen, but I think in all the debugging I have done the most prevalent reason for it has been someone closing an SPSite or an SPWeb that they pulled from the SPContext (GetContextWeb/Site in v2). So if you see one of these messages, or any terribly vague SharePoint message, I would ask yourself if you are closing an SPSite or SPWeb and if so double check if you should. If you have done that, well read on and hopefully this helps.
Changing the web.config
Well if you have double checked your work and are still seeing the error then there is only one choice. Part the fog of SharePoint's error and take a look at the stack trace for the error. There are two things you will need to do to make this happen.
- Turn off Custom Errors: This tag basically controls what error pages your web site will show when an error occurs. In most cases you would not want to show a full stack trace to the world when an error occurs so I would opt for setting this to On for most of the time and RemoteOnly when you want to debug something. If it is a dev only system though knock yourself out and set it to Off. You can set this tag in the <system.web> tag though it should already exist for you to modify. More info on the tag here.
- On: This will always show a simple error has occured page and will not show details.
- RemoteOnly: This will show a simple error has occured page to remote clients and a full stack trace to a browser from the local server.
- Off: This shows a full stack trace to everyone when an error occurs.
- Ex: <customErrors mode="RemoteOnly" />
- Set the SafeMode CallStack: This is my favorite setting for SharePoint, but it comes with a price. You can set the CallStack to true, and it will do wonders for tracking down many errors that otherwise result in the "An unknown error" type messages, however it has a dark side. It can also hide other errors. I have used this method to trace issues in code in SharePoint v2 and found that a fully reproducable case was "fixed" by setting the CallStack to true. Hardly what I was looking for when I did it, but worth noting that this is not a silver bullet for all unknown error messages. Setting this attribute can mask some poor coding standards by making SharePoint slightly more lenient in its memory cleanup and allocation. You can find the <SafeMode> tag in the <SharePoint> tag in the web.config. CallStack in an attribute inside that tag. By default it is set to false. To enable printing of the stack trace just set it to true.
- Ex: <SafeMode MaxControls="50" CallStack="true"/>
|
|
|
|
|
|
|
|
|
|
 |
 |
 |
 |
|