Decoding Sandboxed Solutions Error Messages

So, you’ve built your web part for your SaaS Intranet, you’ve built some amazing solution that does all these whizzy things and it all works. But, but at some undeterminable point after this, execution stops with “Web Part Error: Sandboxed Code Execution Request Failed”. This is a generic error message which circumvents your try-catch. Not a very informative error message!

Lets bring in our good friend JavaScript to save SharePoint yet again! We will create a pop up in JS to show the error message. here’s the code:

string MyScript = @"<script language='javascript'>alert({0});</script>";
try
{
   //Your code
}
catch (Exception ex)
{
   if (!Page.IsClientScriptBlockRegistered("DebugScript")) 
   {
     MyScript = String.Format(MyScript, ex.ToString());
     Page.RegisterClientScriptBlock("DebugScript", MyScript);
   }
}

If this doesnt work use Page.ClientScript.RegisterStartupScript instead of IsClientScriptBlockRegistered

Or If you box has internet access download the Visual Studio 2010 SharePoint Power Tools!

Advertisements

One thought on “Decoding Sandboxed Solutions Error Messages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s