none
Sandbox solution error: partial trust app domain

    Question

  • I have this wsp solution which i am trying to dynamically create a couple custom list. But whenever i do that, it will throw the partial trust app domain error. Does anyone know how I can get around that?

                   // setup custom lists
                    SPWeb oWeb = site.AllWebs[0];
                    if (oWeb != null)
                    {
                        try
                        {
                            SPList oTileList = oWeb.Lists["Tiles"];
                            if (oTileList == null)
                            {
                                oWeb.Lists.Add("Tiles", "A master list containing all the tiles showing on landing page", SPListTemplateType.GenericList);
                                SPList tileList = oWeb.Lists["Tiles"];
                                SPFieldUrl fldURLImage = (SPFieldUrl)tileList.Fields.CreateNewField(SPFieldType.URL.ToString(), "Cover");
                                fldURLImage.DisplayFormat = SPUrlFieldFormatType.Image;
                                tileList.Fields.CreateNewField(SPFieldType.URL.ToString(), "Url");
                                tileList.Update();
                            }
    
                            SPList oQuickLinksList = oWeb.Lists["QuickLinks"];
                            if (oQuickLinksList == null)
                            {
                                oWeb.Lists.Add("QuickLinks", "A master list containing all quicklinks showing on landing page right side column", SPListTemplateType.GenericList);
                                SPList QuickLinksList = oWeb.Lists["QuickLinks"];
                                QuickLinksList.Fields.CreateNewField(SPFieldType.URL.ToString(), "Url");
                                QuickLinksList.Update();
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }

    Thursday, July 21, 2016 3:43 AM

Answers

All replies

  • Hi,

    As I checked the code in your post, it seems that the logic is incorrect.

    Inside the code, it checks if the list exists. If the list does not exist, then throw error; if the list exists, it would do nothing as the condition “if (oTileList == null)” would not meet forever.

    Please modify the code as below:

                    SPWeb oWeb = site.AllWebs[0];
                    if (oWeb != null)
                    {
                        try
                        {
                            SPList oTileList = oWeb.Lists["Tiles"];
                        }
                        catch (Exception ex)
                        {
                            oWeb.Lists.Add("Tiles", "A master list containing all the tiles showing on landing page", SPListTemplateType.GenericList);
                            SPList tileList = oWeb.Lists["Tiles"];
                            SPFieldUrl fldURLImage = (SPFieldUrl)tileList.Fields.CreateNewField(SPFieldType.URL.ToString(), "Cover");
                            fldURLImage.DisplayFormat = SPUrlFieldFormatType.Image;
                            tileList.Fields.CreateNewField(SPFieldType.URL.ToString(), "Url");
                            tileList.Update();
                        }
                    }
    

    In addition, I would recommend you to create an app to achieve this goal instead.

    https://msdn.microsoft.com/en-us/library/office/fp142379.aspx

    Best Regards,

    Victoria


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, July 22, 2016 8:01 AM
    Moderator
  • Why would “if (oTileList == null)”  never meet? If would hit it if the list doesn't exist, wouldn't it?
    Monday, July 25, 2016 4:15 AM
  • Hi,

    Because if the list does not exist, when executing this line "SPList oTileList = oWeb.Lists["Tiles"];", the exception will be thrown, so it will execute the catch part directly instead.

    So it will not execute "if (oTileList == null)" part.

    More reference about try-catch:

    https://msdn.microsoft.com/en-us/library/0yd65esw.aspx

    Best Regards,

    Victoria 


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, July 25, 2016 5:25 AM
    Moderator
  • Hi wll6568,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    Best Regards,

    Victoria


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Saturday, August 6, 2016 2:15 AM
    Moderator