Microsoft Developer Network > Forenhomepage > SharePoint - Design and Customization > error "object reference not set to an instance of an object" when open custom webpart in sharepoint Designer
Stellen Sie eine FrageStellen Sie eine Frage
 

Frageerror "object reference not set to an instance of an object" when open custom webpart in sharepoint Designer

  • Donnerstag, 2. Juli 2009 14:35AshishKumarVerma TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Hi All

    I have created custom webparts and use these webparts into Moss site and it is working fine, but when we try to open the page(which contains custom webparts), into Sharepoint Designer then error "object reference not set to an instance of an object" is displayed at the Webparts and Webparts are not able to visible in Sharepoint Designer.

    Please Suggest the solution.

    Thanks
    Ashish

Alle Antworten

  • Donnerstag, 2. Juli 2009 14:55Mike Walsh MVPMVP, ModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    spd questions go to Design/customization

    Moving this


    WSS FAQ sites: http://wssv2faq.mindsharp.com and http://wssv3faq.mindsharp.com
    Total list of WSS 3.0 / MOSS 2007 Books (including foreign language) http://wssv3faq.mindsharp.com/Lists/v3%20WSS%20FAQ/V%20Books.aspx
  • Donnerstag, 2. Juli 2009 15:11ccvalenc TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    I´m not sure, but if you use the context maybe on designer context be null and because of it, give you this error.

    What kind of webpart or operations do? Can you put some code?
    Microsoft MCP 6608628
  • Freitag, 3. Juli 2009 11:28AshishKumarVerma TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    We have created custom webpart which is inherited from Microsoft System.web.ui.webcontrols.webparts.Webpart class.
    like this

    public class CustomWebPart01 : WebPart
    {
    implementation code
    }

     I have also remove the use of SPcontext to pick site url and start picking site URL from web.config fileas using appsettings, but still the same error has woccurs.

  • Freitag, 3. Juli 2009 14:16Dave Hunter TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Can you edit an out of the box webpart with SPD?  Just trying to find out if its a code issue with your custom webpart or a SPD issue?  If you can edit a standard webpart, can you post your code for your custom webparts?

    Dave
    My SharePoint Blog - http://www.davehunter.co.uk/blog
  • Mittwoch, 8. Juli 2009 13:47AshishKumarVerma TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    Hi

    I have tried a lot and come to know that when I put my custom web part dll into bin directory of the the web site and then add custom web part to the web page of the site and open the page (containing custom web part) in sharepoint designer is displaying fine.
    but when i put same dll into GAC(C:\windows\assembly) and add custom web part to the web page of the site and open it in the sharepoint designer then error "object reference not set to an instance of an object" occurs.
    Means the same dll is working fine from bin directory of the site.

    But the requirement is to put the dll in the GAC(C:\windows\assembly), so please suggest the solution.
    code for the custom web part dll is as follows

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using System.Web;
    using System.Net;
    namespace Test
    {
        public class CustomWebPart01 : WebPart
        {
            private TeamwareServiceInfo twSvcInfo;
            private string _strTwSrvUrl = "";
            //Default Constructor
            public CustomWebPart01()
            {
                Settings twSettings = (Settings)HttpContext.Current.Application[Def.TeamwareSettings];
                twSvcInfo = twSettings.DefaultTwSvcInfo;
                _strTwSrvUrl = twSvcInfo.ToString();

            }
            private string _strDefaultUrl = "";
            private string _strWidth = "100";
            private string _strHeight = "100";

            //Custom property to display URL in property sheet.
            [WebBrowsable(true),
            WebDescription("Displays a custom message"),
            WebDisplayName("To specify a link, type a URL or path."),
            Personalizable(PersonalizationScope.User)]

            public string DisplayMessage
            {
                get
                {
                    return _strDefaultUrl;
                }
                set
                {
                    _strDefaultUrl = value;
                }
            }

            //Custom property for width in the property sheet.
            [WebBrowsable(true),
            WebDescription("Display IFrame width in %"),
            WebDisplayName("Enter IFrame Width[%] "),
            Personalizable(PersonalizationScope.User)]

            public string FrameWidth
            {
                get
                {
                    return _strWidth;
                }
                set
                {
                    _strWidth = value;
                }
            }

            //Custom property to display height in the property sheet.
            [WebBrowsable(true),
            WebDescription("Display IFrame Height in %"),
            WebDisplayName("Enter IFrame Height[%] "),
            Personalizable(PersonalizationScope.User)]

            public string FrameHeight
            {
                get
                {
                    return _strHeight;
                }
                set
                {
                    _strHeight = value;
                }
            }

            //overriding the systems default CreateChildControls method
            protected override void CreateChildControls()
            {
                string _strRequestUrl = "";

                //Code for picking default setting
                if ((_strDefaultUrl == "") && (_strTwSrvUrl != ""))
                {
                    _strDefaultUrl = _strTwSrvUrl;
                }
                else if (_strTwSrvUrl != "")
                {
                    int nPos = _strDefaultUrl.IndexOf("//");
                    string _strTemp = "";
                    int nPos1 = -1;
                    if (nPos != -1)
                    {
                        nPos1 = _strDefaultUrl.IndexOf('/', nPos + 2);
                        if (nPos1 != -1)
                        {
                            _strTemp = _strDefaultUrl.Substring(nPos1 + 1);
                        }
                    }
                    _strDefaultUrl = _strTwSrvUrl + _strTemp;
                }
                if (_strDefaultUrl != "")
                {
                    int nPos = _strDefaultUrl.IndexOf("//");
                    int nPos1 = -1;
                    if (nPos != -1)
                    {
                        nPos1 = _strDefaultUrl.IndexOf('/', nPos + 2);
                        if (nPos1 != -1)
                        {
                            _strRequestUrl = _strDefaultUrl.Substring(0, nPos1);
                        }
                        else
                        {
                            _strRequestUrl = _strDefaultUrl;
                        }
                    }
                }
                base.CreateChildControls();
                HtmlGenericControl twoFrame = new HtmlGenericControl("iframe");
                twoFrame.ID = "IEFrame";

                //Code to check that temaware server is running or not
                //Commented code is for proxy settings.
                try
                {
                    HttpWebResponse _httpWbResponse = null;
                    HttpWebRequest _httpWbRequest = null;
                    if (_strRequestUrl != "")
                    {
                        _httpWbRequest = (HttpWebRequest)WebRequest.Create(_strRequestUrl);
                        _httpWbRequest.ServicePoint.ConnectionLimit = 50;
                        _httpWbRequest.Timeout = 200000;
                        _httpWbResponse = (HttpWebResponse)_httpWbRequest.GetResponse();
                        if ((_httpWbResponse.StatusCode == HttpStatusCode.OK))
                        {
                            twoFrame.Attributes.Add("src", _strDefaultUrl);
                        }
                    }

                }
                catch (Exception)
                {
                    twoFrame.Attributes.Add("src", "/_LAYOUTS/ErrorMessages.aspx");
                }
                //End
                twoFrame.Attributes.Add("width", _strWidth + "%");
                twoFrame.Attributes.Add("height", _strHeight + "%");
                twoFrame.Attributes.Add("frameborder", "0");
                twoFrame.Attributes.Add("border", "0");
                this.Controls.Add(twoFrame);
            }
           
        }
    }


    Thanks
    Ashish