UPDATE ON LOCAL COPY INFO: https://bloggingaccident.com/content/more_on_global_dll_use
So, I’ve got code I want to reuse in SharePoint. It references DirectoryServices, so it has to be signed and trusted, which means building a DLL and storing it in the GAC.
I was a little perplexed on how to reference this in a SP web part though.
I found an article here: http://www.sharepointblogs.com/michael/archive/2007/07/06/sharepoint-sol… that is a good start.
While working with it, I received the error:
“Page Viewer Web Part: The Web Part you attempted to add no longer exists in the Closed Web Parts Gallery. Refresh your browser to update the Web Part Page and the Gallery.”
Thanks to a suggestion found at the end of this post: http://forums.technet.microsoft.com/en-US/sharepointadmin/thread/8397937… I checked my logs and it couldn’t find the .webpart file.
In the process of all of these shenanigans, the property to keep my helper dll set to local copy got changed back to False but that was easy enough to fix.
Oh, and I learned if you ever need to retract your solution manually, go to Central Administration–>Operations–>Solution Management. Sometimes, stsadm doesn’t cut it. 😉
In the end, I had to find a kludgey way to fix this:
I deployed the helper dll to the GAC and added a reference to the web.config file in the SafeAssembly section.
I added a reference to the helper dll in the web part project and set it to Local. I added the code to reference that and rebuilt and redeployed the project.
This worked!
Although I did receive an error that the web part wasn’t secure and couldn’t be displayed when I tried this on my second project. (“A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.”)
I think this could have been due to my changing the namespace on the second project to match the first. (Removing and re-adding the web part to the web part page fixed this.)
Other options you could try:
– Remove and re-add the dll
– Verify it is set to Local Copy=true
– Check the web.config and Assembly just to be sure the Gremlins (or some unwitting coder working on my laptop, in my case) hasn’t removed those references)
– Comment out the code that used the helper file to make sure that is the piece causing the error.