pnp / PnP-Provisioning-Schema

Office 365 Patterns and Practices - Remote Provisioning Schema
MIT License
160 stars 219 forks source link

ClientSidePage adding SPFx webpart to modern page generating Error Could not load type 'System.Web.UI.HtmlTextWriter' #605

Open RasheedSiriyala opened 1 year ago

RasheedSiriyala commented 1 year ago

Hi All,

I'm adding SPFx webpart to modern page using ClientSidePage from OfficeDevPnP.Core C# Console application as in below method,

public bool addSPFxWebpartToModernPage(ClientContext ctx, string pageName) {
try { OfficeDevPnP.Core.Pages.ClientSidePage p = ClientSidePage.Load(ctx, pageName);

            // get a list of possible client side web parts that can be added
            var components = p.AvailableClientSideComponents();

            // Find SPFx webpart "SimpleWP" web part
            var myWebPart = components.Where(s => s.ComponentType == 1 && s.Name == "SimpleWP").FirstOrDefault();
            if (myWebPart != null)
            {
                // Instantiate a client side web part from our found web part information
                OfficeDevPnP.Core.Pages.ClientSideWebPart helloWp = new ClientSideWebPart(myWebPart) { Order = -1 };
                // Add the custom client side web part to the page
                p.AddControl(helloWp);
            }

            // Persist the page to SharePoint
            p.Save(pageName);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

following error is generating at the line p.Save(pageName); "Could not load type 'System.Web.UI.HtmlTextWriter' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.":"System.Web.UI.HtmlTextWriter"

ClientContext ctx is generated as below, using (ClientContext ctx = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, clientID, clientSecret))

and I'm passing valid SharePoint page name.

Resolution to this error is most appreciated. Thanks in advance.

VadhwanaParth15 commented 1 month ago

i am also facing the same problem