Exception in FeatureInstalled calling SharePointServiceLocator

Dec 17, 2010 at 3:19 PM

One of our devs suddenly is having a problem deploying our sharepoint solution from powershell or VS 2010.

 

public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
            var serviceLocator = SharePointServiceLocator.GetCurrent();
}

Even if everything is commented out to just this, it throws the following exception on deploy:
Found 1 deployment conflict(s).  Resolving conflicts ...
  Deleted file 'http://mia-spdv21/_catalogs/wp/MyWebPart.webpart' from server.
  Adding solution 'MyProject.SharePoint.DocViewer.wsp'...
  Deploying solution 'MyProject.SharePoint.DocViewer.wsp'...
Error occurred in deployment step 'Add Solution': Value cannot be null.
Parameter name: type
Exception occurred in vssphost4.exe process: Value cannot be null.
Parameter name: type
Exception Type Name: System.ArgumentNullException
Exception Stack Trace:    at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLocator.CreateInstanceFromTypeMapping(TypeMapping typeMapping)
   at Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator.FindAndCreateConfiguredType[TService](IEnumerable`1 configuredTypeMappings)
   at Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator.GetServiceLocatorFactory(IEnumerable`1 configuredTypeMappings)
   at Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator.CreateServiceLocatorInstance()
   at Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator.GetCurrentFarmLocator()
   at Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator.DoGetCurrent()
   at Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator.GetCurrent()
   at MyProject.SharePoint.DocViewer.Features.ServiceLocator.ServiceLocatorEventReceiver.FeatureInstalled(SPFeatureReceiverProperties properties)
   at Microsoft.SharePoint.Administration.SPFeatureDefinition.DoInstallationCallout(SPSite site, String solutionHash, Boolean fInstall)
   at Microsoft.SharePoint.Administration.SPFeatureDefinition.Install(SPSite site, String solutionHash)
   at Microsoft.SharePoint.Administration.SPFeatureDefinitionCollection.AddCore(SPFeatureDefinition featdef, SPSite site, String solutionHash, Boolean fForce, Boolean fDoValidation)
   at Microsoft.SharePoint.Administration.SPFeatureDefinitionCollection.AddInternal(String relativePathToFeatureManifest, Guid solutionId, String solutionHash, SPSite site, Boolean force, Boolean fDoValidation, SPFeatureDefinitionContext featureDefinitionContext)
   at Microsoft.SharePoint.Administration.SPSolutionPackage.AddFeatureDefinitions(SPFeatureDefinitionCollection featColl, SPFeatureDefinitionContext context, Boolean force, Boolean activateFeatures, SPSite site, SPWeb web)
   at Microsoft.SharePoint.Administration.SPSolutionLanguagePack.InstallFeatures(SPWebApplication webApp, Boolean force, DeploymentConfig config)
   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, Boolean checkIfDeployed)
   at Microsoft.SharePoint.Administration.SPSolutionLanguagePack.DeployLocal(Boolean globalInstallWPPackDlls, Collection`1 webApplications, Boolean force)
   at Microsoft.VisualStudio.SharePoint.Commands.SolutionDeploymentManager.DeploySolution(SPSolution solution, String name)
Exception Message: Value cannot be null.
Parameter name: type
Exception Type Name: Microsoft.VisualStudio.SharePoint.SharePointCommandException
Exception Stack Trace:    at Microsoft.VisualStudio.SharePoint.Commands.SharePointConnection.ThrowExceptionIfMessageFaulted(Message message)
   at Microsoft.VisualStudio.SharePoint.Commands.SharePointConnection.ExecuteCommandInternal(Message requestMessage)
   at Microsoft.VisualStudio.SharePoint.Commands.SharePointConnection.ExecuteCommandInternal[T,TResult](String commandId, CommandFlags flags, T arg)
   at Microsoft.VisualStudio.SharePoint.Commands.SharePointConnection.ExecuteCommand[T](String commandId, T arg)
   at Microsoft.VisualStudio.SharePoint.ProjectSharePointConnection.ExecuteCommand[T](String commandId, T arg)
   at Microsoft.VisualStudio.SharePoint.SharePointProjectCommands.AddSolution(ISharePointConnection connection, SolutionInfo solutionInfo)
   at Microsoft.VisualStudio.SharePoint.Deployment.AddSolutionStep.Execute(IDeploymentContext context)
   at Microsoft.VisualStudio.SharePoint.Deployment.ConfigurationExecutor.Execute()
   at Microsoft.VisualStudio.SharePoint.Deployment.WspDeploymenHandler.Deploy()
========== Build: 5 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========

Coordinator
Dec 18, 2010 at 6:27 PM

THis one is hard to debug on just the stack trace.  IT appears to me that its likely there is an invalid configuration still around for a custom service locator.  Its failing when the service locator factory is constructed.  Are you using the standard service locator, or a custom implementation?  THe code where it is failing would indiciate that a mapping exists for the service locator factory. 

  The following red highlight is where it tries to create a custom service locator in the stack trace. 

        private static IServiceLocatorFactory GetServiceLocatorFactory(IEnumerable<TypeMapping> configuredTypeMappings)
        {
            // Find configured factory. If it's there, creat it.
            var factory = FindAndCreateConfiguredType<IServiceLocatorFactory>(configuredTypeMappings);

            // If there is no configured factory, then the ActivatingServiceLocatorFactory is the default one to use
            if (factory == null)
            {
                factory = new ActivatingServiceLocatorFactory();
            }

            return factory;
        }

The red line below is being called when it fails, which indicates it had a mapping for a custom service locator factory, and is trying to create the custom factory.

         private static TService FindAndCreateConfiguredType<TService>(IEnumerable<TypeMapping> configuredTypeMappings)
            where TService : class
        {
            TypeMapping mapping = FindMappingForType<TService>(configuredTypeMappings);
            if (mapping == null)
                return null;

            return (TService) ActivatingServiceLocator.CreateInstanceFromTypeMapping(mapping);
        }