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.