Servicelocator causing Activate Features to fail

Dec 14, 2010 at 11:36 PM

I had been messing around wiring up structuremap to servicelocator using my own service locator factory.  It was deployed and working.  Then i removed the project in my solution, rolled back after decided to stick to the default one.

Now ANY time I try to touch the servicelocator, in the standard way, and deploy my feature, it says

Error 4 Error occurred in deployment step 'Activate Features': Could not load file or assembly 'StructureMap.ServiceLocatorAdapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f7b27969b51a43b' or one of its dependencies. The system cannot find the file specified. 0 0 (my projectname)

I read it stores the config in propertybags, is there any way to get in there and fix the default servicelocator configuration and remove this old factory mapping to my missing dll?  I even tried putting the dll back out there with no luck.

Coordinator
Dec 15, 2010 at 12:09 AM

This is an issue with lingering configuration.  It still contains a type mapping it is trying to load for the service locator factory.  When you created your custom service locator you did something like the following:

IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
IServiceLocatorConfig typeMappings =
serviceLocator.GetInstance<IServiceLocatorConfig>();
typeMappings.RegisterTypeMapping<IServiceLocatorFactory,   
MyServiceLocatorFactory>();

SharePointServiceLocator.Reset();

You now need to remove that mapping.  You don't have to use the service locator to load the type mappings.  You can directly construct the ServiceLocatorConfig class.  Then remove the type mapping for the IServiceLocatorFactory interface.

typeMappings.RemoveTypeMapping<IService1>(null);

The default service locator is not registered via config, but rather is automatically added.  Once you remove the mapping, the default service locator will then pick up.

Chris

Dec 15, 2010 at 8:57 PM

Bingo, thanks for the workaround.

So now everything works great, and I layered in structuremap which works great.  I run it on my machine, works great, locator working as expected, same on other dev boxes, but when we deploy the package (via PS) to another server, the service locator bombs trying to find my assemblies (repository tier class in a seperate dll from presenter class)

All my assemblies are included in the package, signed, marked safe and allowpartialtrust.

The logs just say :

12/15/2010 14:32:53.46 w3wp.exe (0x156C)                       0x132C SharePoint Foundation         Runtime                       tkau Unexpected Microsoft.Practices.ServiceLocation.ActivationException: No type mapping was registered for type 'IDocumentViewerRepository' and key ''.    at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLocator.DoGetInstance(Type serviceType, String key)     at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) 6931ce9a-8b0b-4084-9fa1-111daa7075a0

I also noticed trying to add some logging when I call:

SharePointServiceLocator.GetCurrent().GetInstance<ILogger>().TraceToDeveloper("In here logging");         

It gives an error:  No Default Instance defined for IPropertyBagHierarchy

This isnt one of the 7 loadtypemappings types, whats going on here?

Coordinator
Dec 15, 2010 at 9:09 PM

For the first case, it sounds like you may have a dependency issue on feature activation?  Is it possible that something is trying to get the IDocumentViewerRepository before the feature containing the IDocumentViewerRepository has activated and registered itself with the service locator?

For the second case, I think what is happening is that structmap is being to smart, and trying to use a constructor for ConfigManager or for HierarchicalConfig that takes an IPropertyBagHierarchy.  The class internally will manage getting the appropriate reference, and this constructor should not be used - this constructor is used for unit testing.  There is no default constructor for the property bag hierarchy because the hierarchy to use depends upon context.  The class HierarchyBuilder is a factory to construct the right stack based upon context.  I have seen this issue before, but not sure how to work around it - can you tell

Dec 15, 2010 at 9:49 PM
Edited Dec 15, 2010 at 10:11 PM

Ok, rolled back to standard servicelocator.

I removed the ctor param.

I register it like this in feature activator:

 var serviceLocator = SharePointServiceLocator.GetCurrent(currentSite);

var typeMapper = serviceLocator.GetInstance<IServiceLocatorConfig>();          

typeMapper.RegisterTypeMapping<IDocumentViewerRepository, DocumentViewerRepository>();

 

It still bombs when I try to resolve it.  I try to resolve it in a presenter class, which is initialized in a web part's controls codebehind:

 public DocumentViewerUserControl()        {            _presenter = new DocumentViewerPresenter(this);        }
 protected void Page_Load(object sender, EventArgs e)        {         _presenter.RetrieveFunds();        }

 

Again it works on developer machines but not on the server.  Any clue why I would still get the type not found?  Looking at the logs I see when the feature is attempted to get registered im getting security exceptions:

Feature Activation: Activating Feature 'MyCompany.SharePoint.DocViewer_ServiceLocator' (ID: '18e07864-d0e5-4a76-be0d-a00a0bf7d57d') at URL http://mia-spts21. f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87 w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       75fb Medium   Calling 'FeatureActivated' method of SPFeatureReceiver for Feature 'MyCompany.SharePoint.DocViewer_ServiceLocator' (ID: '18e07864-d0e5-4a76-be0d-a00a0bf7d57d'). f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87 w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Topology                       8xqz Medium   Updating SPPersistedObject DiagnosticsService. Version: -1 Ensure: False, HashCode: 33468311, Id: 3ac394df-77a3-42ce-8cda-830366fdf35b, Stack:    at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()     at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsService.get_Local()     at Microsoft.Practices.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToTraceFullTrust(String ... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Topology                       8xqz Medium   ...message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.BaseLogger.WriteTraceMessage(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.BaseLogger.TraceToDeveloper(String message, SandboxTraceSeverity severity)     at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.WriteToTraceLog(IPropertyBag propertyBag, String key, String valueAsString)     at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(String key, Object value, IPr... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Topology                       8xqz Medium   ...opertyBag propertyBag)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.SetTypeMappingsList(List`1 typeMappings)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RegisterTypeMapping[TFrom,TTo](String key, InstantiationType instantiationType)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RegisterTypeMapping[TFrom,TTo]()     at MyCompany.SharePoint.DocViewer.Features.ServiceLocator.ServiceLocatorEventReceiver.FeatureActivated(SPFeatureReceiverProperties properties)     at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)     at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, Boolean fForce)     ... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Topology                       8xqz Medium   ...at Microsoft.SharePoint.SPFeatureCollection.AddInternal(SPFeatureDefinition featdef, Version version, SPFeaturePropertyCollection properties, Boolean force, Boolean fMarkOnly)     at Microsoft.SharePoint.SPFeatureCollection.AddInternalWithName(Guid featureId, String featureName, Version version, SPFeaturePropertyCollection properties, Boolean force, Boolean fMarkOnly, SPFeatureDefinitionScope featdefScope)     at Microsoft.SharePoint.SPFeatureCollection.Add(Guid featureId, Boolean force, SPFeatureDefinitionScope featdefScope)     at Microsoft.SharePoint.WebControls.FeatureActivator.ActivateFeature(Guid featid, SPFeatureDefinitionScope featdefScope)     at Microsoft.SharePoint.WebControls.FeatureActivatorItem.BtnActivateFeature_Click(Object objSender, EventArgs evtargs)     at System.Web.UI... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Topology                       8xqz Medium   ....WebControls.Button.OnClick(EventArgs e)     at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)     at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.ProcessRequest()     at System.Web.UI.Page.ProcessRequest(HttpContext context)     at ASP._layouts_managefeatures_aspx.ProcessRequest(HttpContext context)     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()     at System.Web.HttpApplication.ExecuteS... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Topology                       8xqz Medium   ...tep(IExecutionStep step, Boolean& completedSynchronously)     at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)     at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)     at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestConte... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Topology                       8xqz Medium   ...xt, IntPtr moduleData, Int32 flags)     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)   f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87 w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Topology                       8dyu High     The SPPersistedObject, DiagnosticsService, could not be updated because the current user is not a Farm Administrator. f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87 w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     Feature receiver assembly 'MyCompany.SharePoint.DocViewer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=502ad95960b813e0', class 'MyCompany.SharePoint.DocViewer.Features.ServiceLocator.ServiceLocatorEventReceiver', method 'FeatureActivated' for feature '18e07864-d0e5-4a76-be0d-a00a0bf7d57d' threw an exception: Microsoft.Practices.SharePoint.Common.Configuration.ConfigurationException: Configsetting with key 'Microsoft.Practices.SharePoint.Common.TypeMappings' could not be set 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData' with type 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData'. The technical exception was: Microsoft.Practices.SharePoint.Common.Logging.LoggingException: One or more error occurred while writing messages... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ... into the log.\r\nThe error while writing to the EventLog was:An exception has occurred.   ExceptionType: 'SecurityException'   ExceptionMessage: 'Access denied.'   StackTrace: '   at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()       at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsService.get_Local()       at Microsoft.Practices.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)       at Microsoft.Practices.SharePoint.Common.Logging... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ....SharePointLogger.WriteToTraceFullTrust(String message, Int32 eventId, SandboxTraceSeverity severity, String category)       at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category)'   Source: 'Microsoft.SharePoint'   TargetSite: 'Void BaseUpdate()'  \r\n Orginal logged message was: Set value in hierarchical config.\n\tKey: 'Microsoft.Practices.SharePoint.Common.TypeMappings'\n\tLevel: 'CurrentSPSite'\n\tValue: '<?xml version="1.0" encoding="utf-16"?>  <ArrayOfTypeMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <TypeMapping>      <FromAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, Publ... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...icKeyToken=ef4330804b3c4129</FromAssembly>      <FromType>Microsoft.Practices.SharePoint.Common.Logging.ILogger, Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</FromType>      <ToType>Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger, Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</ToType>      <ToAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</ToAssembly>      <InstantiationType>NewInstanceForEachRequest</InstantiationType>    </TypeMapping>    <TypeMapping>      <FromAssembly>MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</FromAssemb... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...ly>      <FromType>MyCompany.SharePoint.DocViewer.Presentation.Model.IDocumentViewerRepository, MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</FromType>      <ToType>MyCompany.SharePoint.DocViewer.Presentation.Model.DocumentViewerRepository, MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</ToType>      <ToAssembly>MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</ToAssembly>      <InstantiationType>NewInstanceForEachRequest</InstantiationType>    </TypeMapping>  </ArrayOfTypeMapping>' ---> Microsoft.Practices.SharePoint.Common.Logging.LoggingException: One or more error occurred while writing messages into t... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...he log.\r\nThe error while writing to the EventLog was:An exception has occurred.   ExceptionType: 'SecurityException'   ExceptionMessage: 'Access denied.'   StackTrace: '   at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()       at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsService.get_Local()       at Microsoft.Practices.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)       at Microsoft.Practices.SharePoint.Common.Logging.ShareP... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...ointLogger.WriteToTraceFullTrust(String message, Int32 eventId, SandboxTraceSeverity severity, String category)       at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category)'   Source: 'Microsoft.SharePoint'   TargetSite: 'Void BaseUpdate()'  \r\n Orginal logged message was: Set value in hierarchical config.\n\tKey: 'Microsoft.Practices.SharePoint.Common.TypeMappings'\n\tLevel: 'CurrentSPSite'\n\tValue: '<?xml version="1.0" encoding="utf-16"?>  <ArrayOfTypeMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <TypeMapping>      <FromAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyTo... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...ken=ef4330804b3c4129</FromAssembly>      <FromType>Microsoft.Practices.SharePoint.Common.Logging.ILogger, Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</FromType>      <ToType>Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger, Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</ToType>      <ToAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</ToAssembly>      <InstantiationType>NewInstanceForEachRequest</InstantiationType>    </TypeMapping>    <TypeMapping>      <FromAssembly>MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</FromAssembly>    ... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...  <FromType>MyCompany.SharePoint.DocViewer.Presentation.Model.IDocumentViewerRepository, MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</FromType>      <ToType>MyCompany.SharePoint.DocViewer.Presentation.Model.DocumentViewerRepository, MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</ToType>      <ToAssembly>MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</ToAssembly>      <InstantiationType>NewInstanceForEachRequest</InstantiationType>    </TypeMapping>  </ArrayOfTypeMapping>' ---> System.Security.SecurityException: Access denied.     at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()    ... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ... at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()     at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsService.get_Local()     at Microsoft.Practices.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToTraceFullTrust(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity sev... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...erity, String category)  The Zone of the assembly that failed was:  MyComputer     --- End of inner exception stack trace ---     at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.BaseLogger.WriteTraceMessage(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.BaseLogger.TraceToDeveloper(String message, SandboxTraceSeverity severity)     at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.WriteToTraceLog(IPropertyBag propertyBag, String key, String valueAsString)     at Microsoft.Practices.SharePoint.Common.Configuration.Config... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...Manager.SetInPropertyBag(String key, Object value, IPropertyBag propertyBag)     --- End of inner exception stack trace ---     at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(String key, Object value, IPropertyBag propertyBag)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.SetTypeMappingsList(List`1 typeMappings)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RegisterTypeMapping[TFrom,TTo](String key, InstantiationType instantiationType)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RegisterTypeMapping[TFrom,TTo]()     at MyCompany.SharePoint.DocViewer.Features.ServiceLocator.ServiceLocatorEventReceiver.FeatureActivated(SPFeatureReceiverProperties ... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Feature Infrastructure         88jm High     ...properties)     at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce) f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87 w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     Feature Activation: Threw an exception, attempting to roll back.  Feature 'MyCompany.SharePoint.DocViewer_ServiceLocator' (ID: '18e07864-d0e5-4a76-be0d-a00a0bf7d57d').  Exception: Microsoft.Practices.SharePoint.Common.Configuration.ConfigurationException: Configsetting with key 'Microsoft.Practices.SharePoint.Common.TypeMappings' could not be set 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData' with type 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData'. The technical exception was: Microsoft.Practices.SharePoint.Common.Logging.LoggingException: One or more error occurred while writing messages into the log.\r\nThe error while writing to the EventLog was:An exception has occurred.   ExceptionType: 'SecurityException'   Excepti... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...onMessage: 'Access denied.'   StackTrace: '   at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()       at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsService.get_Local()       at Microsoft.Practices.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)       at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToTraceFullTrust(String message, Int32 eventId, SandboxTraceSeverity severity, String category)       at Microso... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...ft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category)'   Source: 'Microsoft.SharePoint'   TargetSite: 'Void BaseUpdate()'  \r\n Orginal logged message was: Set value in hierarchical config.\n\tKey: 'Microsoft.Practices.SharePoint.Common.TypeMappings'\n\tLevel: 'CurrentSPSite'\n\tValue: '<?xml version="1.0" encoding="utf-16"?>  <ArrayOfTypeMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <TypeMapping>      <FromAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</FromAssembly>      <FromType>Microsoft.Practices.SharePoint.Common.Logging.ILogger, Microsoft.Practices.Sh... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...arePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</FromType>      <ToType>Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger, Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</ToType>      <ToAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</ToAssembly>      <InstantiationType>NewInstanceForEachRequest</InstantiationType>    </TypeMapping>    <TypeMapping>      <FromAssembly>MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</FromAssembly>      <FromType>MyCompany.SharePoint.DocViewer.Presentation.Model.IDocumentViewerRepository, MyCompany.SharePoint.DocViewer.Presentati... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...on, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</FromType>      <ToType>MyCompany.SharePoint.DocViewer.Presentation.Model.DocumentViewerRepository, MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</ToType>      <ToAssembly>MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</ToAssembly>      <InstantiationType>NewInstanceForEachRequest</InstantiationType>    </TypeMapping>  </ArrayOfTypeMapping>' ---> Microsoft.Practices.SharePoint.Common.Logging.LoggingException: One or more error occurred while writing messages into the log.\r\nThe error while writing to the EventLog was:An exception has occurred.   ExceptionType: 'SecurityException'   ExceptionMessa... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...ge: 'Access denied.'   StackTrace: '   at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)       at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()       at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsService.get_Local()       at Microsoft.Practices.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)       at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToTraceFullTrust(String message, Int32 eventId, SandboxTraceSeverity severity, String category)       at Microsoft.Prac... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...tices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category)'   Source: 'Microsoft.SharePoint'   TargetSite: 'Void BaseUpdate()'  \r\n Orginal logged message was: Set value in hierarchical config.\n\tKey: 'Microsoft.Practices.SharePoint.Common.TypeMappings'\n\tLevel: 'CurrentSPSite'\n\tValue: '<?xml version="1.0" encoding="utf-16"?>  <ArrayOfTypeMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <TypeMapping>      <FromAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</FromAssembly>      <FromType>Microsoft.Practices.SharePoint.Common.Logging.ILogger, Microsoft.Practices.SharePoin... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...t.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</FromType>      <ToType>Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger, Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</ToType>      <ToAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</ToAssembly>      <InstantiationType>NewInstanceForEachRequest</InstantiationType>    </TypeMapping>    <TypeMapping>      <FromAssembly>MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</FromAssembly>      <FromType>MyCompany.SharePoint.DocViewer.Presentation.Model.IDocumentViewerRepository, MyCompany.SharePoint.DocViewer.Presentation, Ver... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...sion=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</FromType>      <ToType>MyCompany.SharePoint.DocViewer.Presentation.Model.DocumentViewerRepository, MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</ToType>      <ToAssembly>MyCompany.SharePoint.DocViewer.Presentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee26c2b3ceb3c767</ToAssembly>      <InstantiationType>NewInstanceForEachRequest</InstantiationType>    </TypeMapping>  </ArrayOfTypeMapping>' ---> System.Security.SecurityException: Access denied.     at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()     at Microsoft.SharePoint.Administration.SPDiagnosticsServi... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...ceBase.GetLocalToFarm[T](SPFarm farm)     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()     at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsService.get_Local()     at Microsoft.Practices.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToTraceFullTrust(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category)  The Zone of the assembly that failed was:  MyComputer     --- End of inner exception stack trace ---     at Mi... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...crosoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.BaseLogger.WriteTraceMessage(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.BaseLogger.TraceToDeveloper(String message, SandboxTraceSeverity severity)     at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.WriteToTraceLog(IPropertyBag propertyBag, String key, String valueAsString)     at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(String key, Object value, IPropertyBag propertyBag)     --- End of inner exception stack trace ---     at Micr... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...osoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(String key, Object value, IPropertyBag propertyBag)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.SetTypeMappingsList(List`1 typeMappings)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RegisterTypeMapping[TFrom,TTo](String key, InstantiationType instantiationType)     at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RegisterTypeMapping[TFrom,TTo]()     at MyCompany.SharePoint.DocViewer.Features.ServiceLocator.ServiceLocatorEventReceiver.FeatureActivated(SPFeatureReceiverProperties properties)     at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)     at Microsoft.SharePoint.SP... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.87* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         General                       72by High     ...Feature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, Boolean fForce) f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.88 w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Monitoring                     b4ly High     Leaving Monitored Scope (Feature Activation: Activating Feature 'MyCompany.SharePoint.DocViewer_ServiceLocator' (ID: '18e07864-d0e5-4a76-be0d-a00a0bf7d57d') at URL http://mia-spts21.). Execution Time=44.1675 f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.88 w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Runtime                       tkau Unexpected System.Security.SecurityException: Access denied.    at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)     at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()     at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsService.get_Local()     at Microsoft.Practices.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)     at Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToTraceFullTrust(String message, Int32 eventId, SandboxTraceSeverity severity, String category)     at Microsoft.Prac... f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.88* w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Runtime                       tkau Unexpected ...tices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId, SandboxTraceSeverity severity, String category) f003b536-a634-492f-b87b-fdb6b94c3a2812/15/2010 17:05:36.88 w3wp.exe (0x10B8)                       0x1BA0 SharePoint Foundation         Monitoring                     b4ly Medium  

Coordinator
Dec 16, 2010 at 12:34 PM

I believe I see two issues in the above stack trace:

- You must register your services in the FeatureInstalled event.  Registering services writes to the farm level configuration, which is not permitted from a content web, and that is where FeatureActivated will often run.  The documentation appears incorrect in this regard.  I let the team know it needs to be updated.

- You must register the events for the event log on each web front end.  This is true when using the SharePoint logging - this is not a specific requirement of the p&p logger, it's a dependency on the underlying SharePoint logging infrastructure.  The content web doesn't have sufficient permission to create the events for the event log, which writes to the registry.  There is a helper class for this as well, DiagnosticsAreaEventSource.  You can either do this from a command line app, or you can write a timer job.  Let me know if you need an example for a timer job and I will write a blog post with an example.

Dec 16, 2010 at 3:04 PM
Edited Dec 16, 2010 at 6:55 PM


If you could post about the logging that would be nice I don't really follow what your saying, sorry I am a SharePoint n00b.

Sometimes this thing works, others it doesnt.  I flipped it to a feature installation, here is my code, now its blowing up on the new mapping i just added.  This is KILLING me.  Any ideas?  I removed the site specific stuff since you said this now is firing when the farm is getting setup.

Error after simply adding another registration... what is going on!?!

12/16/2010 13:52:35.40 w3wp.exe (0x03D8)                       0x15B0 SharePoint Foundation         Runtime                       tkau Unexpected Microsoft.Practices.ServiceLocation.ActivationException: No type mapping was registered for type 'ITreeFactory' and key ''.    at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLocator.DoGetInstance(Type serviceType, String key)     at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) a112050c-6705-4663-804e-12bc53f7063b

public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
//            var currentSite = properties.Feature.Parent as SPSite;
//            IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(currentSite);
            var serviceLocator = SharePointServiceLocator.GetCurrent();
            
            var typeMapper = serviceLocator.GetInstance<IServiceLocatorConfig>();
//            typeMapper.Site = currentSite;
            typeMapper.RegisterTypeMapping<IRepositoryFactory, RepositoryFactory>();
            typeMapper.RegisterTypeMapping<ITreeFactory, TreeFactory>();
        }

 

Dec 16, 2010 at 7:18 PM

Ok I figured this out I think.

Adding that to featureinstalled/uninstalled is right.

But now I have to make sure in our deployment scripts that we deactive/remove everything including feature and reinstall from scratch so this code fires.  Now that I am doing that I *think* I am good, I will reply if I hit more issues.

 

If you have any info on that logging that would be a nice to have too!  

 

Thanks again for all the help!

Coordinator
Dec 17, 2010 at 2:15 PM

good news greg.  I don't think I'll make it to that today, but I'll try to get it done this weekend, and post back here when it's complete.

Dec 17, 2010 at 3:19 PM

Sounds great.

Another dev is now having random exceptions deploying the same code others of us are using now regarding this same code that now works for me, CI, and other devs.

Can you take a look at this issue, your help would be most appreciated again :)

http://spg.codeplex.com/Thread/View.aspx?ThreadId=238752

 

Coordinator
Dec 20, 2010 at 7:42 PM

I added a blog post on using a timer job to create the event sources.  http://blogs.msdn.com/b/chriskeyser/archive/2010/12/20/using-a-sharepoint-timer-job-to-deploy-settings-in-a-farm-for-registering-event-sources.aspx.

Chris

Dec 21, 2010 at 7:22 PM
Edited Dec 21, 2010 at 7:52 PM

Chris,


Thanks I will check that out.  I have another issue though.  We successfully uninstall/reinstall our package now with powershell scripts.  But everytime I add some new mapping to my servicelocator, I start getting the same error again

Unexpected Microsoft.Practices.ServiceLocation.ActivationException: No type mapping was registered for type 'IDocGroupingFactory' and key ''.    at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLocator.DoGetInstance(Type serviceType, String key)     at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) a8946c15-c4f3-4e30-8592-3247804296e9

It is in there and runs on dev machines fine.  Why is it anytime I add a new type to it I get these issues???

This must be the feature is having some issue installing and running our code, but I don't understand why.  Our install does the following, is this the right way to upgrade the feature on the server?

Disable-SPFeature $sharepoint_feature_folder_name -Url $sharepoint_server -Confirm:$false

Uninstall-SPFeature $sharepoint_feature_folder_name -force -Confirm:$false

Uninstall-SPSolution -Identity $sharepoint_package_file_name -WebApplication $sharepoint_server -Confirm:$false

Remove-SPSolution -Identity $sharepoint_package_file_name -force -Confirm:$false

Add-SPSolution $sharepoint_project_output_directory$sharepoint_package_file_name

Install-SPSolution -Identity $sharepoint_package_file_name -WebApplication $sharepoint_server -GACDeployment

Install-SPFeature $featurefolderpath$sharepoint_feature_folder_name -force

Enable-SPFeature $featurefolderpath$sharepoint_feature_folder_name -Url $sharepoint_server

 

Coordinator
Dec 22, 2010 at 5:25 PM

Here is I think the issue that you are facing.  If you are not installing the settings with a farm scoped feature, then the settings are still cached.  We cache the farm scoped mappings for performance reasons.  There are three things you can do here.  The first is to install as a farm scoped feature.  I'm fairly certain that should cause all of the app domains to recycle when the farm scoped feature is activated.  The second approach will be to flush the cache by recycling IIS on the WFE's in your farm.  The third approach would be to customize the logic to periodically reload the farm settings (this is already being done for the site settings).  You can manually force the reload as well by calling SharePointServiceLocator.Reset(), but this will only cause the farm configuration to reload in the app domain it is called from.

I had wanted to add some logic to reload the cached settings whenever a type failed to load, but the process to do that ended up being too complicated to implement for this release.

Dec 23, 2010 at 2:48 PM

This makes sense because if we run the install twice it seems to work lol.

So when should the iis reset come into play in this order:

Disable-SPFeature $sharepoint_feature_folder_name -Url $sharepoint_server -Confirm:$false

Uninstall-SPFeature $sharepoint_feature_folder_name -force -Confirm:$false

Uninstall-SPSolution -Identity $sharepoint_package_file_name -WebApplication $sharepoint_server -Confirm:$false

Remove-SPSolution -Identity $sharepoint_package_file_name -force -Confirm:$false

IIS Reset here???

Add-SPSolution $sharepoint_project_output_directory$sharepoint_package_file_name

Install-SPSolution -Identity $sharepoint_package_file_name -WebApplication $sharepoint_server -GACDeployment

Install-SPFeature $featurefolderpath$sharepoint_feature_folder_name -force

Enable-SPFeature $featurefolderpath$sharepoint_feature_folder_name -Url $sharepoint_server

IIS Reset here???

Jan 6, 2011 at 3:03 PM

Chris,

 

We tried to deploy at the farm level, it says you cannot do that with a webpart, is that true?  If so can I solve the issue with IIS resets?

Coordinator
Jan 7, 2011 at 1:21 AM

Hi Greg -Not sure I fully understand -  web parts are deployed in a site scoped feature typically.  You would have to have a different feature that is farm scoped if you were taking that approach.  They could be in the same solution package, but would be different features.

Jan 7, 2011 at 5:30 PM

So Chris as I understand, put one feature in to setup the service locator, then leave the feature that deploys the webpart as is and remove the setup from that receiver?

 

Also now, another wonderful thing started happening:

Error 1 Error occurred in deployment step 'Add Solution': Configsetting with key 'Microsoft.Practices.SharePoint.Common.TypeMappings' could not be set 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData' with type 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData'. The technical exception was: Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException: An update conflict has occurred, and you must re-try this action. The object FarmSettingStore Name=_pnpFarmConfig_ was updated by SharePointDevGF\Greg Fricke, in the vssphost4 (8540) process, on machine SHAREPOINTDEVGF.  View the tracing log for more information about the conflict.
  0 0 LpPortal.SharePoint.DocViewer 

I saw in some bug items on codeplex to use this to get rid of it, is this ok to use? 

FarmSettingStore.DeleteStore(SPFarm.Local);

 

 

Coordinator
Jan 7, 2011 at 6:03 PM

Yes, that is my recommmendation - to put the configuration into a separate farm scoped feature.  In general I think it makes as well from a design viewpoint since its likely that many of your services will be used by more than one web part eventually.

It's disappointing you are seeing that error, we put a lot of effort into making the logic more resilient on update and we also tested under heavy load without seeing the exception.  This exception is thrown by SharePoint.  Basically config is stored as a blob, and if more than one piece of logic changes it at a time, this exception occurs.  You can see in config manager the following logic:

               for (int retryCnt = 0; retryCnt < maxRetryCount && !savedConfig; retryCnt++)
                {
                    // if multiple writes occur concurrently to the property bag for an object at the same time, SharePoint will throw.
                    // catch that exception and retry saving the configuration a few times before giving up.
                    try
                    {
                         propertyBag[fullKey] = valueAsString;
                         savedConfig = true;
                         if (retryCnt > 0)
                         {
                             this.Logger.TraceToDeveloper(string.Format("ConfigManager: Saved to config after retry to '{0}' level, retry count: '{1}', key: '{2}'", propertyBag.Level, retryCnt, key),
                                 SandboxTraceSeverity.High);
                         }
                    }
                    catch (Exception ex)
                    {
                        if (ExceptionManaged(ex))
                        {
                            savedException = ex;
                            this.Logger.TraceToDeveloper(string.Format("ConfigManager: Failure saving config to '{0}' level, retry count: '{1}', key: '{2}'", propertyBag.Level, retryCnt, key),
                                SandboxTraceSeverity.High);
                        }
                        else
                            throw;
                    }
                }

I don't know what would be causing so many writes that you'd see this exception.  You can try to add some logic on top of this with a random backoff time.  I had considered doing that but it did appear to be necessary based upon our stress testing.

 

Jan 7, 2011 at 6:49 PM

Yea it is odd, and this is on my local box, and only I deploy from visual studio, it just randomly happened starting yesterday after i ran the app, stopped, made a change in a webpage, reran, boom, thats it!?!?!  Now its popping up randomly.

 

Is there anything wrong with using this to get rid of it in the event receiver before my registrations take place?

FarmSettingStore.DeleteStore(SPFarm.Local);

Coordinator
Jan 7, 2011 at 7:03 PM

That will nuke any settings that you have in the farm.  So its OK as long as you want to wipe all settings you made through configuration manager, or to the service locator configuration.

Coordinator
Jan 7, 2011 at 7:04 PM

Also if you can make a consistent repro of the error, let me know and I will try to take a look at it.

Jan 7, 2011 at 8:54 PM

Heh yea its happening more and more now, but once again i run, stop it, make some arbitrary tweak to my codebase/ascx, run again, boom

Coordinator
Jan 7, 2011 at 9:53 PM

I have a feeling it may be something exacerbating this in your code.  Do have mutliple instances of the configuration created that you are updating about the same time in your code?

Jan 7, 2011 at 9:54 PM

Nope, just in the feature, i havent moved it to farm level yet as we discussed, and this hasnt changed in the last month, this error just randomly pops since yesterday, and the only thing I have been touching in the last day is some javascript and html on the 1 web part my project has...

Jan 18, 2011 at 11:38 PM

Chris,

We created a new feature, wire up the service locator there, and only install the web part in the other feature.

Same issue, on deployment the service locator is not setup with new items.  We again have to run deployment 2x then it works.

Does there need to be a delay or something else in there?  We have a whole bunch of IIS Resets everywhere too with no luck.  We are supposed to go live in a week and it is embarassing to have to have a client run an install 2x to get this to work...

Coordinator
Jan 19, 2011 at 1:12 AM

hmm.  would you mind posting a code snippet to this thread?  I don't know why you need to run it 2x.  If you can post a repro case I will do my best to propose a resolution.  You should not need to do this twice.  If you have a reproducible case I should be able to run this down for you tomrrow.

Jan 19, 2011 at 3:03 PM

Chris,

Just an fyi, this seems to happen on some servers not others, is there a timer setting or something like caching that could be the root of this?  Our dev machines, SharePoint win 7 boxes, don't have the issue.  Our permissions and configuration are the same on the server, which is win2k8 r2.

Here is the service locator code:

  [Guid("fc5026fb-4faa-43d7-b6ee-e8b867d19ec0")]
    public class ServiceLocatorEventReceiver : SPFeatureReceiver
    {
        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            var serviceLocator = SharePointServiceLocator.GetCurrent();
            var typeMapper = serviceLocator.GetInstance<IServiceLocatorConfig>();
            typeMapper.RegisterTypeMapping<IFoo, Foo>();
            //many others
        }


        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            var serviceLocator = SharePointServiceLocator.GetCurrent();
            var typeMapper = serviceLocator.GetInstance<IServiceLocatorConfig>();
            typeMapper.RemoveTypeMapping<IFoo>(null);
            //many others
        }
    }

We use powershell and a psake script to install it, is that something I can email you?

 

Coordinator
Jan 19, 2011 at 4:09 PM

You can email me at ckeyser@microsoft.com.

This looks innocuous.  There is a timer that runs to deploy the solution, which will cause the farm scoped feature to be installed and activated (this is standard SharePoint).  It will take some time for the feature components to get deployed to all of the WFE's - again standard SharePoint.  The feature installed event receiver however will only fire a single time on one of the WFE's.  This will write the configuration informaton using SPPersistedObject, which is in turn persisted to the configuration database.

As I understand your issue, you are deploying the solution, and then the service settings are not being picked up, so you redeploy.  Is it the case that the settings are not detected on any of the WFE's, or only some of the WFE's?

This definitely feels like a race to me, and indeterminate sequencing.  I don't know if SharePoint honors ordering unless you have feature dependencies in place.  I'm wondering if some of the components that get deployed are starting before the settings are deployed - therefore the cached inforation is not correct.  I think adding a dependency on the settings feature may help solve the issue, only I think there may be an issue having a dependence between a site and farm scoped feature  - I'd have to do some research on that.

One other thing you can do is get rid of the caching in the service locator code (this is pretty easy).  You could also wrapper the service locator, and reset it once if the type isn't found.  THis would help work around the problem if its an issue with the cached info.  I wanted to get this into the last release, however dealing with it in the current design was too complicated to get out in time.  I will try to prototype a wrapper today for you.

Coordinator
Jan 20, 2011 at 10:05 PM

I added a blog post on how to use a wrapper class to make the service locator more resilient to configuration changes.  See http://blogs.msdn.com/b/chriskeyser/archive/2011/01/20/handling-sharepointservicelocator-failures-due-to-caching.aspx.

Developer
Jan 20, 2011 at 10:30 PM

Thanks!

From: ckeyser [email removed]
Sent: Thursday, January 20, 2011 2:06 PM
To: Hanz Zhang
Subject: Re: Servicelocator causing Activate Features to fail [spg:238390]

From: ckeyser

I added a blog post on how to use a wrapper class to make the service locator more resilient to configuration changes. See http://blogs.msdn.com/b/chriskeyser/archive/2011/01/20/handling-sharepointservicelocator-failures-due-to-caching.aspx.

Dec 9, 2011 at 3:58 AM
ckeyser wrote:

I believe I see two issues in the above stack trace:

- You must register your services in the FeatureInstalled event.  Registering services writes to the farm level configuration, which is not permitted from a content web, and that is where FeatureActivated will often run.  The documentation appears incorrect in this regard.  I let the team know it needs to be updated.

- You must register the events for the event log on each web front end.  This is true when using the SharePoint logging - this is not a specific requirement of the p&p logger, it's a dependency on the underlying SharePoint logging infrastructure.  The content web doesn't have sufficient permission to create the events for the event log, which writes to the registry.  There is a helper class for this as well, DiagnosticsAreaEventSource.  You can either do this from a command line app, or you can write a timer job.  Let me know if you need an example for a timer job and I will write a blog post with an example.


Hi,

Is there any way to do this in feature activated?  It seems like the real reason to use this is so that I can change the provider at run time, via a feature activation for instance. I can actually do it and it will work, but only when I deploy the wsp via Visual Studio with auto activation.  I really don't want to have an admin have to run a power shell script, or have to hit central admin to swap my provider.

 

Here is my code:

IServiceLocatorConfig typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>();
IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
typeMappings.RemoveTypeMapping<IContextService>(null);

The error that happens if I try to toggle the feature activation in site settings:

Configsetting with key 'Microsoft.Practices.SharePoint.Common.TypeMappings' could not be set 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData' with type 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData'. The technical exception was: System.Security.SecurityException: Access denied.

 

Dec 9, 2011 at 2:34 PM
jmillman wrote:
ckeyser wrote:

I believe I see two issues in the above stack trace:

- You must register your services in the FeatureInstalled event.  Registering services writes to the farm level configuration, which is not permitted from a content web, and that is where FeatureActivated will often run.  The documentation appears incorrect in this regard.  I let the team know it needs to be updated.

- You must register the events for the event log on each web front end.  This is true when using the SharePoint logging - this is not a specific requirement of the p&p logger, it's a dependency on the underlying SharePoint logging infrastructure.  The content web doesn't have sufficient permission to create the events for the event log, which writes to the registry.  There is a helper class for this as well, DiagnosticsAreaEventSource.  You can either do this from a command line app, or you can write a timer job.  Let me know if you need an example for a timer job and I will write a blog post with an example.


Hi,

Is there any way to do this in feature activated?  It seems like the real reason to use this is so that I can change the provider at run time, via a feature activation for instance. I can actually do it and it will work, but only when I deploy the wsp via Visual Studio with auto activation.  I really don't want to have an admin have to run a power shell script, or have to hit central admin to swap my provider.

 

Here is my code:

IServiceLocatorConfig typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>();
IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
typeMappings.RemoveTypeMapping<IContextService>(null);

The error that happens if I try to toggle the feature activation in site settings:

Configsetting with key 'Microsoft.Practices.SharePoint.Common.TypeMappings' could not be set 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData' with type 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationConfigData'. The technical exception was: System.Security.SecurityException: Access denied.

 


I actually got it to work without error by setting the site to the current site in feature activation.  While this does get around the error, the service doesn't swap out until I do an iisreset.  Is there any way to swap the service on the fly?

Coordinator
Dec 9, 2011 at 9:35 PM

hmm....if you are setting the site, then it will save the type mapping at the site collection level, not the farm level.  Since this operation stores the settings for the site collection level in the property bag of the root site it will work.  If you did not set the site, then the type mappings are stored to the farm property bag.  SharePoint prevents writing to the farm property bag from a content web, so it will cause a security exception if you try to do this from feature activated (unless it is a farm scoped feature).  Also you really only want to register the setting once - what happens if you activate the feature in mulitple places within the farm?

In order to clear the cache for the service locator, call the Reset method - this will clear the cache.