Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm in the process of creating a sandboxed web part, during debugging though once it is on the site the web part displays the error shown below:

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.

Now I've searched for this error but have thus far found little information. I've checked the list of restrictions, but I'm pretty sure I'm ok there unless System.Web.UI.Controls is not allowed. You can find my code below and any help would be appreciated.

using System.ComponentModel;
using System.Web.UI.WebControls;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;

    namespace FPContentQueryCustom.FrontCusWebPart
    {
        [ToolboxItemAttribute(false)]
        public class FrontCusWebPart : System.Web.UI.WebControls.WebParts.WebPart 
        {
            public FrontCusWebPart()
            {
            }

            protected override void CreateChildControls()
            {
                SPWeb thisWeb = SPContext.Current.Web;
                SPListCollection siteLists = thisWeb.Lists;

                siteLists.ListsForCurrentUser = true;

                DataTable dt = new DataTable();
                dt.Columns.Add("data");

                foreach (SPList list in siteLists)
                {

                    SPListItemCollection listItem = list.Items;

                    foreach (SPListItem item in listItem)
                    {
                        dt.Rows.Add(item.DisplayName);
                    }
                }

                dt.AcceptChanges();

                SPGridView grid = new SPGridView();
                grid.ID = "ExampleGrid";
                grid.AutoGenerateColumns = false;

                BoundField col = new BoundField();
                col.DataField = "data";
                col.SortExpression = "data";
                col.HeaderText = this.DisplayTitle;
                grid.Columns.Add(col);

                grid.DataSource = dt;
                grid.DataBind();

                Controls.Add(grid);
            }
        }
    }
share|improve this question
    
After some more debugging got the issue pinned down to an unhandled exception thats occuring with SPGridView, so not sure whats causing it as yet. –  Anonymous Aug 26 '10 at 15:21

6 Answers 6

up vote 0 down vote accepted

This is a generic error. Sometimes you have a plus-sign in front of the error that allows you to see more details about it.

Check the ULS logs for more details. Also as James says - use debugging - just hit F5 and set a break point in your code.

share|improve this answer
    
There has been no plus infront of the error, I'll check the ULS, to see what it says. Further to that I have been running the code in debug mode using F5 and setting up break points at the start of the code however these have not been firing. –  Anonymous Aug 25 '10 at 15:19

Try adding the AllowPartiallyTrustedCallers attribute to your code:

using System.Security;
[assembly: AllowPartiallyTrustedCallers]
namespace FPContentQueryCustom.FrontCusWebPart
share|improve this answer

I think to help debug this and other solutions, you can set a breakpoint in your code and attach to SPUCHostService.exe`, which should hit the breakpoint upon executing the code in your solution.

I suggest this because there might not be an issue with the restrictions in sandbox solutions and your code, but a logic problem in your code itself which is throwing an exception.

` = EDIT: As Wictor suggested, just add a breakpoint and hit F5, no there's need to attach to the process in 2010.

share|improve this answer

I also face the same issue, using SPgridView, u can use Gridview instead of SPGridView then it should solve ur problem. Regards Sri

share|improve this answer

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.

If you attach the code to SPUCHostService.exe using F5, then this error is thrown after RenderControl method . So, not sure for where error is coming...

Any help on this. Thanks in advance

share|improve this answer

I don't think SPGridView is supported in Sandbox

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.