<solution> deployment error to the GAC: Error: Cannot add the specified assembly to the global assembly cache, reverting to local bin and use of CAS

I have been having a strange error with the deployment of a solution to MOSS 2007. On my local machine the solution gets installed and deployed nicely however when I move it to staging server it returns an error:

Error: Cannot add the specified assembly to the global assembly cache: [myassemblyname.dll].   at Microsoft.SharePoint.Administration.SPSolutionPackage.UpdateGacFile(SolutionFile file, String sourcePath, Boolean install)
   at Microsoft.SharePoint.Administration.SPSolutionPackage.UpdateFiles(String vrPath, Boolean install)
   at Microsoft.SharePoint.Administration.SPSolutionPackage.EnableWebApplication(String vrPath, Boolean globalInstall, TextWriter logWriter, Boolean force)
   at Microsoft.SharePoint.Administration.SPSolutionLanguagePack.DeploySolutionPackage(SPWebApplication webApp, Boolean globalInstall, Boolean force, String& errMsg)
   at Microsoft.SharePoint.Administration.SPSolutionLanguagePack.DeployFilesInstallFeatures(SPWebApplication webApp, Boolean globalInstallWPPackDlls, Boolean installFeatures, Boolean force, Int32 tries)
   at Microsoft.SharePoint.Administration.SPSolutionLanguagePack.DeployLocalCore(Boolean globalInstallWPPackDlls, Collection`1 webApplications, Boolean useAdminService, Boolean force)
   at Microsoft.SharePoint.Administration.SPSolutionLanguagePack.DeployLocal(Boolean globalInstallWPPackDlls, Collection`1 webApplications, Boolean force)
   at Microsoft.SharePoint.ApplicationPages.SolutionPageBase.CreateDeploymentJob(Boolean deploy, String strSelectedWeb, Boolean globalInstall, DateTime dt, Boolean localDeployment)
   at Microsoft.SharePoint.ApplicationPages.DeploySolutionPage.BtnSubmit_Click(Object sender, EventArgs e)
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 

After having searched for answers and posted a question on the MSDN forum: still nothing. Seems I’m the only one having this error, at least for the time being :-(

My solution to this problem is adding the assemblies to the local bin of the application. I have read that this is the recommended approach.
However using this approach there is an important aspect to take into account: the CAS (code access security) permission set. When an assembly is deployed to the GAC it runs with Full trust. When deploying to the web application's bin directory the assembly runs with minimal trust. It is necessary to add CAS (Code Access Security) elements to the <solution> schema in order to set the right permissions.

My solutions are being deployed nicely now, it was a small challenge to find the correct security settings to implement however. I finally found some nice blog posts with a few samples and found the correct settings.

CAS itself is actually something in ASP.NET, not just SharePoint.

Some of my resources for CAS:

 

[Update 26-Aug-2007] While installing solutions with DLLs to the GAC I'm still having this problem from time to time on one single machine. My solution for the moment is rebooting the server and running the install solution script again. Luckily it's only the staging server presenting this issue so a reboot is not so much an issue.

 

Technorati tags:

Feedback

Posted on 16 May 2007 @ 15:15

You are not alone.

We're having the same issue, "once in a while".

Occasionally the GAC appears to be "broken" - happens on both development and production servers.
Symptoms:
- Error like you describe
- C:\Windows\Assembly is empty (scary stuff!)
- gacutil -l lists nothing
- gacutil add assembly does not work
- you can browse the correct GAC through the MMCs
- it does not go away on its own... ;-)

Solutions:
- If the failure started when you deploy something in your own context (i.e. stsadm -o deploysolution -local...) you can just relogin.
- If not a server reboot will fix the problem. For the time being. It will most likely popup again at later stage.

Hope it helps.

Posted on 28 May 2007 @ 11:38

Hi søren,
It's nice to finally have someone also encountering the same issues. Thanks a lot for your tips.

Katrien

Posted on 02 November 2007 @ 20:10

Out of curiosity do you have resharper installed? i noticed this at a client site when they had resharper running on the ide, it was locking the GAC

Posted on 03 November 2007 @ 15:46

No Resharper installed on either machine where I had this problem.

Posted on 27 May 2008 @ 06:43

Guys,
I have the same problem and - yes I also have resharper 3.0.2 installed.

Posted on 26 February 2009 @ 01:07

I had similar problems with my IDE when deploying to the GAC. I had ReSharper installed in my VS2005, and it would intermittently lock up the GAC, preventing the deployment of the wsp (it would error out).

Ultimately, my solution was to disable ReSharper whenever this started happening. Or close my IDE. Or go on a coffee break. Or ultimately, restart the machine. It is certainly MUCH more frequenty a problem with ReSharper installed.

Posted on 05 March 2009 @ 02:52

I've actually found doing an IIS reset before running the deployment releases the hold on the GAC and allows the deployment to go ahead no problems.

Posted on 22 September 2009 @ 11:20

check this URL

http://www.davehunter.co.uk/Blog/Lists/Posts/Post.aspx?List=f0e16a1a%2D6fa9%2D4130%2Dbcab%2Dbaeb97ccc4ff&ID=101

ie Start/Restart the windows sharepoint services administration.

Do this operation on your front end server.From windows atart menu>>Select Run>>Type "services.msc">>Start the service "windows sharepoint services administration"

Posted on 28 April 2010 @ 11:22

Closing Visual Studio and restarting the "windows sharepoint services administration" service solved my problem

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Copyright © 2007 Katrien De Graeve.