Webpart deployment error: object reference not set to an instance of an object
-
Saturday, May 12, 2007 11:17 AM
Trying to deploy my custom web part from visual studio 2005. First time when i deploying its getting deployed and working perfectly fine but as i do some changes and trying to deploying it again it is giving the following error:
Object reference not set to an instance of an object
Does anybody have an idea why it is giving this error. Any help on this would be really appreciated.
Answers
-
Thursday, June 14, 2007 9:21 PM
I found a way to solve this some what. This will only work if your webpart is already deployed to sharepoint. (Basically experiencing the problem where you can not re-deploy it). Also note this will only work if you are developing on the sharepoint server.
First what you need to do is goto the folder you project builds to. (eg bin\Debug). Open notepad and save your document in the Debug folder, but save it as "install.bat" instead of with the txt extension. Okay now in the .bat file you need to add 3 lines:
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf nameofdll
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if nameofdll.dll
iisreset
where nameofdll and nameofdll.dll is the name of the dll for your project. Make sure you save this. Basically the first line uninstalls the dll from the GAC, the second line installs it to the GAC and the last line resets IIS.
Next goto your project's Properties, then go to the Build Events tab. In the Post-Build box type install.bat
Now your ready to go. All you need to do is build your project and your sharepoint will have the updated version. Just remember everytime you build this will run that .bat file, so it will restart IIS each time. Hope this helps some of you out, just saves some manual work.
All Replies
-
Friday, May 18, 2007 3:00 PM
Yeah, i'm getting the same error too.
Was able to build and deploy web part (several times) in the past, but now i am getting the Object Ref. error on deploy.
I have been using the Build menu options for Build "Project Name" and Deploy "Project Name".
To iterate, any help would be much appreciated.
- Proposed As Answer by Manolo HerreraMVP Friday, October 03, 2008 6:24 PM
-
Tuesday, May 29, 2007 8:33 PM
This seems to be happening to a few people. Here is what I am doing as a work around. If you look in the bin folder there is a batch file called setup.bat. It is a pain, but you can remove and deploy the part by opening the command prompt and navigating to the bin folder. Enter
Code Snippetsetup /uninstall
orCode Snippetsetup /install
to remove or deploy the solution. This is not installing the assembly in the GAC so you will still need to do this manually. As a refresher go to start, then run and type 'assembly'. Just drag and drop your assembly there. Or as an alternative you can add some lines to the setup.bat, for example:Code Snippet@rem----------------------------------------------------------------------
@rem LDeploy
@rem----------------------------------------------------------------------
:LDeploy
echo Adding solution %PackageName% to the SharePoint ...
"%SPAdminTool%" -o addsolution -filename "%PackageFile%"echo Deploying solution %PackageName% ...
"%SPAdminTool%" -o deploysolution -name "%PackageName%" -local -allowGacDeployment -url %TargetWebUrl%echo Activating feature WebPart5 ...
"%SPAdminTool%" -o activatefeature -id 5be720ad-e963-404d-8026-2eecb5c4f6d0 -url %TargetSiteUrl%"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if WebPart5.dll
iisreset
goto :EOF
Here is another post http://forums.microsoft.com/msdn/showpost.aspx?postid=1257801&SiteID=1
-
Thursday, May 31, 2007 6:33 AM
Guys - I was also receiving this error. (which is painful - as it just starts usually after a successful install/deploy of a solution - for me)
Here's a tip to help to try and track it down - as you know the Sharepoint Template Designer that gets added to VS.NET Sharepoint based projects (project->properties) does some pretty funky things and dynamically generates alot of the deployment bits needed to deploy your solution.
(e.g. walks through and grabs all the webparts, ids, features and builds a file ready for deployment from them)
Running the Setup.bat file for me - worked everytime.
During a 'deploy' from VS.NET, check the 'Output window' as the dynamic building/compilation results appears here.
You will most probably have the error printed (we hope

My case was - the 'template' is setup to deploy to a site collection at http://<servername>/
I'm doing a MS Project Server solution and my site collection is at http://<servername>/projectserver
I adjusted this within Setup.bat (there is an option to do this under Project PRoperties->Debug, has no effect on deployment)
Hope I've helped to shed some light on this - it can be a bit of a brick wall.
Cheers,
Mick.
-
Thursday, May 31, 2007 10:55 AM
Deployment of webpart
If you get an "Object reference not set to an instance of an object" error, Check in the Project Properties in the debug tag
that that the option "Start browser in URL" is set to an valid web site. If it is set to an valid website redirect it to another website that is also in the
sharepoint farm. It should deploy the webpart to your site aswell.
-
Thursday, May 31, 2007 7:38 PM
Still have same error, dont change anything... ity does that to any page I try to put my custom webpart on. Im using VSeWSS.. just wrote a simple thing to text, new project, webpart, ... just to show a text and still does it... Dont understand.. I was able to fine and then suddently nothing work anymore after I tried to add my webpart to another site...
Ive tried to add
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if WebPart5.dll
iisreset
in the setup.bat but dont change anything
-
Thursday, May 31, 2007 8:28 PM
Hi Fred,
The WebPart5.dll in the PostBat should be the name of your webpart dll. Which can be located in either project properties or in the bin directory.
-
Thursday, May 31, 2007 8:57 PMIt did not work.. I will try the path you told me in your next post.. will start form scratch.. mabye will be fine
-
Thursday, June 14, 2007 9:21 PM
I found a way to solve this some what. This will only work if your webpart is already deployed to sharepoint. (Basically experiencing the problem where you can not re-deploy it). Also note this will only work if you are developing on the sharepoint server.
First what you need to do is goto the folder you project builds to. (eg bin\Debug). Open notepad and save your document in the Debug folder, but save it as "install.bat" instead of with the txt extension. Okay now in the .bat file you need to add 3 lines:
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf nameofdll
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if nameofdll.dll
iisreset
where nameofdll and nameofdll.dll is the name of the dll for your project. Make sure you save this. Basically the first line uninstalls the dll from the GAC, the second line installs it to the GAC and the last line resets IIS.
Next goto your project's Properties, then go to the Build Events tab. In the Post-Build box type install.bat
Now your ready to go. All you need to do is build your project and your sharepoint will have the updated version. Just remember everytime you build this will run that .bat file, so it will restart IIS each time. Hope this helps some of you out, just saves some manual work.
-
Wednesday, June 27, 2007 6:09 AM
I am in the process of starting a community WSSWiki and one of the first articles I have posted on there is to resolve the "Object reference not set to an instance of an object" issue with the Visual Studio Extensions for WSS (VSeWSS).
Try the solution out and let me know if it works for you as it did for me (this is unsupported by Microsoft, so please do not do this in your production environment):
http://www.wsswiki.com/Visual_Studio_Extensions_For_WSS_3.0
Thank you,
Paul Liebrand
-
Wednesday, June 27, 2007 11:57 PM
Tyler, your post helped me considerably. I just ran into this today. Very nasty bug.
Now I can get back to building with the IDE.
Thanks
-
Thursday, March 13, 2008 11:00 AM
HI, all
I couldn't make the tyler file work (it was giving always the same problem with or wothou the dll in gac).
At the contrary, the MissingFeature Utility on the link in the next comment, is very useful.
I advice it!
Bye
-
Friday, October 03, 2008 6:24 PM
Just Run Vs2005 as administrator. Right click in the shortcout and select Run as Administrator, if you want to save this option, choose Properties, Advanced and select Run as Administrator.
Hope this works, for me it works!.- Proposed As Answer by pankajj sharmaa Thursday, November 05, 2009 12:49 AM
-
Thursday, April 09, 2009 5:06 PMRun as administrator - that was the ticket!

