1

I have SharePoint solution, which contains template, multiple libraries, web-parts and etc... In this case I have found a bug in one of my web-parts. How I can only update that one web-part, so I can fix the bug?

I think that I need to create Visual Studio project which contains only web-part. I don't have Visual Studio in my production server, so I cannot use it to deploy solution. How I can deploy webpart.wsp correctly to solution? Do I have to remove someway web-part first or what is to correct way fix web part?

Can you please guide me, how I can fix it?


After I run Update-SPSolution, SharePoint web-parts gives me an error message: $Resources:core,ImportErrorMessage;

I checked that web-part feature is activated and it can be found in Site settings / Web Designer Galleries / Web parts. But if I try open it, it gives me same error message.

I used SharePointLogViewer:

Error importing WebPart. Assembly EBIC SPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=90615eedf85cc25e, TypeName. Full_Template.WebParts.PersonalItems.PersonalItems. $Resources:core,ImportErrorMessage;

Application error when access /_layouts/15/WPPrevw.aspx, Error=Object reference not set to an instance of an object. at Full_Template.WebParts.PersonalItems.PersonalItems.<>c__DisplayClass5.<.ctor>b__0() at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.b__3() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Full_Template.WebParts.PersonalItems.PersonalItems..ctor()

System.NullReferenceException: Object reference not set to an instance of an object. at Full_Template.WebParts.PersonalItems.PersonalItems.<>c__DisplayClass5.<.ctor>b__0() at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.b__3() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Full_Template.WebParts.PersonalItems.PersonalItems..ctor()

Getting Error Message for Exception System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> Microsoft.SharePoint.WebPartPages.WebPartPageUserException: $Resources:core,ImportErrorMessage; ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Full_Template.WebParts.PersonalItems.PersonalItems.<>c__DisplayClass5.<.ctor>b__0() at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.b__3() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCal...

...lback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Full_Template.WebParts.PersonalItems.PersonalItems..ctor() --- End of inner exception stack trace --- at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.Creat...


Web-part is big so I add only parts of code:

Guid siteID = SPContext.Current.Site.ID;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(siteID))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        try
                        {
                            SPList oList2 = web.Lists["config"];
                SPListItemCollection collListItems2 = oList2.Items;
                                foreach (SPListItem item in collListItems2)
                                {
                // LOOP ITEMS
                }
                        catch (Exception ex)
                        {
                            Label label = new Label();
                            label.Text = "DEBUG: " + ex.Message + "INNERDEBUG: " + ex.InnerException.Message;
                            //label.Text = ex.Message;
                            this.Controls.Add(label);
                        }
                    }
                }
            });




SPSite siteColl = SPContext.Current.Site;
                    SPWeb site = SPContext.Current.Web;
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite ElevatedsiteColl = new SPSite(siteColl.ID))
                        {
                            using (SPWeb ElevatedSite = ElevatedsiteColl.OpenWeb(site.ID))
                            {
                                SPUser currUser = site.CurrentUser; //not the ElevatedSite.CurrentUser
                                loggeduser = currUser.ToString();

                                // parse logged user account
                                int i = loggeduser.IndexOf('\\') + 1;
                                string d = loggeduser.Substring(i);
                                d.Substring(1);
                                loggeduser = d;
                            }
                        }
                    });





SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications)
                            {
                                foreach (SPSite siteCollection in webApp.Sites)
                                {
                                    foreach (SPWeb web in siteCollection.RootWeb.GetSubwebsForCurrentUser())
                                    {
                                        if (web.ID.ToString() == orgPageFromUrl)
                                            oWebsite = web;
                                    }
                                }
                            }
                        });
1

If you a wsp like you mentioned webpart.wsp, then you can deploy it on your production server using SharePoint Management shell.

Use powershell if just have to upgrade the solution

Update-SPSolution –Identity "<wsp package name>" -LiteralPath "<physical path of the 
wsp package>" –GacDeployment 
e.g.: Update-SPSolution –Identity "test.wsp" -LiteralPath "C:\test.wsp" –GacDeployment

To add and install use

Add -SPSolution "<WSP Package file path>" 
e.g.: Add -SPSolution "C:\test.wsp"

Install-SPSolution –Identity "<wsp package name>" –WebApplication "<url of web application>" –GACDeployment 
e.g.: Install-SPSolution –Identity "test.wsp" –WebApplication “http://naveen-pc:2711 “ –GACDeployment

To remove and uninstall use

Uninstall-SPSolution –Identity “<wsp package name>” –WebApplication “<url of web application>” 
e.g.: Uninstall-SPSolution –Identity “test.wsp” –WebApplication ”http://naveen-pc:2711/” 

Remove-SPSolution–Identity "<wsp package name>" 
e.g.: Remove-SPSolution–Identity “test.wsp” 

After running command SP-Upgrade, things will work effectively if your wsp already exist in SharePoint farm and your new wsp is error free. If re-deploying or upgrading your new wsp cause error in webpart, the there must be problme in your wsp. As there are just command to upgrade or install your solution in SharePoint.

It's will be better if you first retract and remove that solution. Remove webpart from Page where that webpart is stuck into it. Then Add, Deploy the solution again. Activate the feature, then add webpart in your page. It should work if your solution (wsp) is fine. If not, then there must be error in your wsp.

You can re-deploy your old wsp. I'm assuming you are using any source control like TFS or svn or other thing to manage version of your solution. So take an ols version of wsp and try to deploy it using same command. Webpart will work fine, if it previously work fine!

  • Hey, thanks your advice! I tried Update-SPSolution -Identity Full_Template.wsp -LiteralPath C:\Temp\Full_Template.wsp -GACDeployment. However now my webpart gives me an error message: $Resources:core,ImportErrorMessage; . Any clue how I can fix this? – user21216 Oct 17 '14 at 8:44
  • PS. Full_Template.wsp is farm level – user21216 Oct 17 '14 at 8:50
  • Please post your complete error! And also check that feature is activated or not which provision your webpart to webpart gallery – ateet Oct 17 '14 at 9:14
  • There seems to have an error in code that contain some line sin SPSecurity.RunWithElevatedPrivelge deleaget control in your webpart code. Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Full_Template.WebParts.PersonalItems.PersonalItems..ctor() – ateet Oct 17 '14 at 10:21
  • It's odd because I have only changed catch statement and it worked before Update-SPSolution. However, I add code parts where I have used SPSecurity.RunWithElevatedPrivileges – user21216 Oct 17 '14 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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