Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Unhandled Exception after deactivating a feature

$
0
0

  I have a solution with 3 features to apply custom branding to SharePoint.  The feature that applies a new homepage takes an error when the feature is deactivated.  I have an event receiver that reverts the homepage to the old homepage when the feature is deactivated.  Here are the important points.

1.  This error only occurs when the feature receiver runs and only occurs when my code to revert the home page runs.  

2.  The error does not occur in the code.  The code runs all the way to completion and all code blocks in the feature receiver, appear to be exiting gracefully.  The error just appears when the page attempts to refresh after the post-back. However, refreshing the page after that brings you back to the ManageFeatures.aspx and the feature is no longer active.  So, everything is working, it just shows an error after post-back.

3.  The features can be activated fine and there is a feature receiver on activation that applies the new home page.  That has never taken an error.

Here are the errors from the ULS logs:

Unexpected
System.Web.HttpException: The DataSourceID of 'TopNavigationMenu' must be the ID of a control of type IHierarchicalDataSource.  A control with ID 'topSiteMap' could not be found.   
 at System.Web.UI.WebControls.HierarchicalDataBoundControl.GetDataSource()    
 at System.Web.UI.WebControls.HierarchicalDataBoundControl.ConnectToHierarchicalDataSource()    
 at System.Web.UI.WebControls.HierarchicalDataBoundControl.OnLoad(EventArgs e)  

Verbose
Application error when access /_layouts/ManageFeatures.aspx, Error=The DataSourceID of 'TopNavigationMenu' must be the ID of a control of type IHierarchicalDataSource.  A control with ID 'topSiteMap' could not be found.  
 at System.Web.UI.WebControls.HierarchicalDataBoundControl.GetDataSource()    
 at System.Web.UI.WebControls.HierarchicalDataBoundControl.ConnectToHierarchicalDataSource()    

Here is my code that reverts the home page:

        public static void revertHomepage(string siteUrl, string welcomePage)
        {
            string keyName = "Dsoft_OldhomePage";
            string oldHomepage = null;
            string currentHomepage = null;


            // check web properties for old home page name
            oldHomepage = Pbags.CheckForProperty(siteUrl, keyName, "Web");

            using (SPSite site = new SPSite(siteUrl))
            {                

                    SPWeb web = site.OpenWeb();
                    SPFolder rootFolder = web.RootFolder;
                    currentHomepage = rootFolder.WelcomePage;                    

                    // check to see if we need to revert
                    try
                    {

                        if (oldHomepage != welcomePage && oldHomepage != currentHomepage)
                        {

                            rootFolder.WelcomePage = oldHomepage;
                            rootFolder.Update();


                        }
                    }
                    catch (Exception e)
                    {
                        // Write the error to log
                        SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
                        diagSvc.WriteTrace(0,
                        new SPDiagnosticsCategory("QITC Site BRanding", TraceSeverity.Monitorable, EventSeverity.Error),
                        TraceSeverity.Unexpected, string.Format("Error Getting List Data: {0}", e.Message));
                    }
                    finally
                    {
                        web.Dispose();
                    }

                    // delete from property bag     
                    Pbags.DeleteProperty(siteUrl, keyName, "Web");
            }

        }



Lance


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>