I have created a custom web part which presents a form to create a SharePoint site below the current site, while performing some ancillary actions like updating a list of subsites on the front page to include the newly created subsite.

Development has, as per Microsoft guidelines, been performed on a SharePoint Foundation box which closely resembles the environment in Microsoft Online. Deployment and testing on this test machine is obviously as a sandboxed solution. Before adding the web part to the SharePoint Online gallery, I put a generic try-catch around all my code to be able to pick up any error messages in the production environment, where no debugger is available.

The web part does indeed work (the subsite is created), 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 my try-catch. Presumably, I am doing something that the Sandboxed Code Service doesn't like. But the code works fine in the sandboxed server environment.

Is there any way to get a more specific error message? Does anyone have experience developing sandboxed solutions for SharePoint Online and know if there are any less painful practices? I guess I could do a "manual search" and comment out each individual line of code where my error could be, but this is a ridiculously painful approach.

3 Answers 3


Maybe you could use this to debug? It pops up an alert message with the error in it. (I didn't test this) After removing the bug I would delete this again...

string MyScript = @"<script language='javascript'>alert({0});</script>";
   //Your code
catch (Exception ex)
   if (!Page.IsClientScriptBlockRegistered("DebugScript"))
     MyScript = String.Format(MyScript, ex.ToString());
     Page.RegisterClientScriptBlock("DebugScript", MyScript);
  • Okay, so if I'm reading this correctly you are dynamically registering a script which displays the exception in a JavaScript alert box in the postback? Thanks for the tip, this is a smart way of getting debug information in this environment. I can't get it to work, though. Regardless, it doesn't help my case, since the exception gets swallowed in the first place. For some reason, my problem disappeared in SharePoint online when I added your code, but I'm keeping the question open since this problem is guaranteed to show up again. Nov 10, 2011 at 9:07
  • That's correct. Maybe you could try to use Page.ClientScript.RegisterStartupScript instead of the Page.RegisterClientScriptBlock (there's a difference between them, but don't know what exactly) Nov 10, 2011 at 9:14

I can't remember if its possible or not, but can you enable the Developer Dashboard in SharePoint Online? If so, would that provide you with any additional information that may be useful? (Sorry, I'm not a dev so I'm not completely up to speed on the tool)


Visual Studio SharePoint Power Tools apparently extends Visual Studio to show an error when you are trying to use types or members in a sandboxed project which are not allowed. This should stop you from stepping in any major pitfalls. VSPT also lets you develop Visual Web Parts for the sandboxed code service, which makes developer life a bit easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.