How can I validate a custom web part property in a Sandbox solution (SharePoint Online 2013 environment)?

I am throwing a WebPartPageUserException when validation fails, as shown below.

private string fileName = "test";

Category("Custom Properties"),
WebDisplayName("Template File Name")]
public string TemplateFileName
    get { return fileName; }
        if (string.IsNullOrEmpty(value))
            throw new WebPartPageUserException("Template File Name cannot be empty.");

        fileName = value;

Throwing the WebPartPageUserException exception is breaking the web part; it starts displaying this error message:

Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. Correlation ID: 1e535d9c-0f00-e011-b94d-8fb08e826bea.

ULS logs the below error:

SPNavigationNode previousSibling, PortalSiteMapNode parentNode)    
 at Microsoft.SharePoint.Publishing.Navigation.PortalWebSiteMapNode.PopulateNavigationChildrenInner(NodeTypes includedTypes)    
 at Microsoft.SharePoint.Publishing.Navigation.PortalWebSiteMapNode.PopulateNavigationChildren(NodeTypes includedTypes)    
 at Microsoft.SharePoint.Publishing.CachedArea.CreateRefreshedVersion(List`1& newObjects)    
 at Microsoft.SharePoint.Publishing.CachedObjectFactory.ReSyncChangedCache()".

I thought the error might be related to the left navigation menu, so I tried removing it from the page (just in case). But this did not have any effect.

I have also tried deploying to several different environments and site collections, with no luck.

Can a WebPartPageUserException be thrown from a Sandbox solution? If not, what is the suggested way for handling custom web part property validation?

Thank you for your help.

1 Answer 1


As you guessed, this is not allowed from inside a sandboxed solution.

You're going to have to test the value some way or the other, and maybe render a message to the user inside the webpart itself.

Related question here

  • Thanks @Anima, I thought as much and had in fact seen that related question, but couldn't find anything on MSDN so I thought maybe someone had figured out how to use WebPartPageUserException in Sandbox. :(
    – Rachel
    Dec 6, 2013 at 8:01

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.