1

Resolved

Service Locator: Removal of type previously used for TypeMapping causes breakage

description

I created a custom ILogger, registered it with the service locator, and used it within my custom SharePoint PowerShell cmdlet. (Hence the Service Locator was running at farm level.)
 
I then decided to no longer use the custom logger and removed it from my project. I changed the code to use the default instance for ILogger. Using it from then onwards failed, as the service locator still continued to try loading my custom logger which had been removed. I tried registering the SharePointLogger explicitly and it continued to try loading my custom logger. I also tried using RemoveTypeMapping() and RemoveTypeMappings() and still the problem continued. It appears to always try loading the currently stored type mappings before changing them.
 
Here is the stack trace when trying to use RemoveTypeMappings():
 
mscorlib.dll!System.Activator.CreateInstance(System.Type type, bool nonPublic)
Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLocator.CreateInstanceFromTypeMapping(Microsoft.Practices.SharePoint.Common.ServiceLocation.TypeMapping typeMapping = {Microsoft.Practices.SharePoint.Common.ServiceLocation.TypeMapping}) Line 133 C#
Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLocator.DoGetInstance(System.Type serviceType = {Name = "ILogger" FullName = "Microsoft.Practices.SharePoint.Common.Logging.ILogger"}, string key = null) Line 66 C#
Microsoft.Practices.ServiceLocation.dll!Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(System.Type serviceType = {Name = "ILogger" FullName = "Microsoft.Practices.SharePoint.Common.Logging.ILogger"}, string key = null)
Microsoft.Practices.ServiceLocation.dll!Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance<Microsoft.Practices.SharePoint.Common.Logging.ILogger>()
Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.Configuration.SPFarmPropertyBag.this[string].set(string key = "PnP.Config.Key.Microsoft.Practices.SharePoint.Common.TypeMappings", string value = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfTypeMapping xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" />") Line 178 C#
Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(string key = "Microsoft.Practices.SharePoint.Common.TypeMappings", object value = Count = 0, Microsoft.Practices.SharePoint.Common.Configuration.IPropertyBag propertyBag = {Microsoft.Practices.SharePoint.Common.Configuration.SPFarmPropertyBag}) Line 386 C#
Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.SetTypeMappingsList(System.Collections.Generic.List<Microsoft.Practices.SharePoint.Common.ServiceLocation.TypeMapping> typeMappings = Count = 0) Line 285 C#
Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RemoveTypeMappings<Microsoft.Practices.SharePoint.Common.Logging.ILogger>() Line 199 C#

file attachments

comments

ckeyser wrote Aug 3, 2010 at 1:49 PM

Are you missing some of the stack trace?

I found a bug that is a recent regression from another bug fix we made to address a situation where a setting has not been stored to the farm or web application stores. In this case there was an exception caused when searching the store hierachically for a setting that wasn't defined. The bug I am seeing is caused because of the following:
  • We remove the type setting for the type mapping. The final step is to store the type mappings to the farm configuration store.
  • We log that we have updated the farm configuration store.
When we do the final step, we are using the cached settings for the service locator for type mappings. That cached setting still will have your logger registered. This is a bug, and you caught it because it was the logger that was the affected class on de-registration. I'll need to look at the best way to address it. But your type mapping should have been unregistered, and after recycling IIS the default should have been picked up. You do not need to re-register the default, we automatically register the default logger, and then override that registration if you define a configured logger.

Can you verify that
1) You are doing the unregistering from a context that has farm write permissions (like a console app with admin permissions, or a feature installed/uninstalling event from a web/site scoped feature, or a farm scoped feature activiated/deactivating).
2) If you are doing this from a context with the correct permissions, check if the typemapping is actually unregistered after the exception. You can do this by:
  • catching the exception.
  • SharePointServiceLocator.Reset()
  • var logger = SharePointServiceLocator.GetCurrent().GetInstance<ILogger>();
    Console.WriteLine(logger.GetType().ToString());
The type should be the default implementation.

arangas wrote Aug 4, 2010 at 11:00 PM

Thanks for your detailed explanation, that gives a pretty good picture about what's going on.

There's nothing missing from the stack trace except the first one which is my custom app calling RemoveTypeMappings().

Regarding point 1: The app is a custom SharePoint PowerShell cmdlet. It has farm write permission, and I could trace through the service locator code to see this wasn't a permissions issue. I could also update the service locator settings again once I resurrected my deleted PowerShellLogger.

Regarding point 2: I found the typemapping wasn't unregistered because I could repeatedly run the app that called RemoveTypeMappings() and found it still failed looking for the non-existent type.

Thanks again and please let me know if I can provide any more info.

wrote Aug 5, 2010 at 5:07 PM

ckeyser wrote Aug 5, 2010 at 5:07 PM

I'm attaching a simple application that registers then unregisters the logger. With the current code, you will see the exception thrown, but you should also see the logger is no longer registered subsequently. This should demonstrate that the unregister does function. Please let me know if you have any problems with this example running. With some recent changes this will work without throwing exceptions, although it will also require that IIS be recycled on the WFE's to pick up the changes.

I will add this to our backlog to make the farm scoped service locator automatically flush as well periodically as the site service locators currently, but I don't know when that will get in.

Thanks,
Chris

arangas wrote Aug 5, 2010 at 11:51 PM

Hi Chris,

Unfortunately the logger is still registered after running your test app.

Would it help if I give you a better example with sample code?

Thanks, Alex.

ckeyser wrote Aug 6, 2010 at 9:00 PM

Please give me a repro case. I'm not sure why this works for me and not for you...we need to figure out what is different about our environments.

wrote Aug 7, 2010 at 12:00 AM

wrote Aug 7, 2010 at 12:01 AM

ckeyser wrote Aug 7, 2010 at 12:01 AM

I'm not sure why you are seeing different behavior than me. I've attached another version that dumps more information on the configuration. Please run this and post the output.

ckeyser wrote Aug 9, 2010 at 3:29 PM

Hi,
Could you please run the last example I provided, and give me the output. I'm dumping configuration information so hopefully I can figure out what is the problem within your setup. The application I provided works for me, and I haven't heard this issue back from others, so I have a feeling it is probably something with your configuration that is causing the issue. I need to understand in more detail what is going on. You can provide an example for me as well, and I'll verify if it does or doesn't work on my side. That will help to further clarify if it is a sequencing issue difference, or if it is an environmental difference. Also are you using the latest version downloaded from the download center? That is the version you should be using, not a codeplex drop.

Thanks,
Chris

wrote Aug 10, 2010 at 12:02 AM

arangas wrote Aug 10, 2010 at 12:02 AM

Hi Chris, Sorry about the delay - CodePlex sent me all your messages yesterday. I am using the official release - files are dated 1 July 2010. They are attached in the ZIP anyway. Attached is a sample piece of code that should reproduce the problem. I can't test it because it is still failing trying to look for that nonexistent logger which my sample doesn't reference. However hopefully it works for you. Perhaps it is not a good example because it doesn't register an ILogger, instead a test interface I made up. So if you can't reproduce please just change the code to register a custom ILogger instead. How to repro is in the code. Running your latest code, I get the following output: ******************************************************************************** Microsoft.Practices.SharePoint.Common.Configuration.ConfigurationException: Conf igsetting with key 'Microsoft.Practices.SharePoint.Common.TypeMappings' could no t be set 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationC onfigData' with type 'Microsoft.Practices.SharePoint.Common.ServiceLocation.Serv iceLocationConfigData'. The technical exception was: Microsoft.Practices.Service Location.ActivationException: Activation error occured while trying to get insta nce of type ILogger, key "" ---> Microsoft.Practices.ServiceLocation.ActivationE xception: Activation error occured while trying to get instance of type ILogger, key "" ---> System.IO.FileNotFoundException: Could not load file or assembly 'A RTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture=neutral, Pub licKeyToken=null' or one of its dependencies. The system cannot find the file sp ecified. File name: 'ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture =neutral, PublicKeyToken=null' at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boo lean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence as semblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString) at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLoc ator.CreateInstanceFromTypeMapping(TypeMapping typeMapping) at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLoc ator.DoGetInstance(Type serviceType, String key) at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Typ e serviceType, String key) === Pre-bind state information === LOG: User = AA\administrator LOG: DisplayName = ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///C:/Temp/ConsoleFeatureInstallTest/ConsoleFeatureInstallTe st/bin/Debug/ LOG: Initial PrivatePath = NULL Calling assembly : Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Cultu re=neutral, PublicKeyToken=ef4330804b3c4129. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Temp\ConsoleFeatureInstallTest\Con soleFeatureInstallTest\bin\Debug\ConsoleFeatureInstallTest.vshost.exe.Config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\ v2.0.50727\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partia l, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Temp/ConsoleFeatureInstallTest/Co nsoleFeatureInstallTest/bin/Debug/ARTC.SharePoint.InvoiceTracking.PowerShell.DLL . LOG: Attempting download of new URL file:///C:/Temp/ConsoleFeatureInstallTest/Co nsoleFeatureInstallTest/bin/Debug/ARTC.SharePoint.InvoiceTracking.PowerShell/ART C.SharePoint.InvoiceTracking.PowerShell.DLL. LOG: Attempting download of new URL file:///C:/Temp/ConsoleFeatureInstallTest/Co nsoleFeatureInstallTest/bin/Debug/ARTC.SharePoint.InvoiceTracking.PowerShell.EXE . LOG: Attempting download of new URL file:///C:/Temp/ConsoleFeatureInstallTest/Co nsoleFeatureInstallTest/bin/Debug/ARTC.SharePoint.InvoiceTracking.PowerShell/ART C.SharePoint.InvoiceTracking.PowerShell.EXE. --- End of inner exception stack trace --- at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Typ e serviceType, String key) at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TSe rvice]() at Microsoft.Practices.SharePoint.Common.Configuration.SPFarmPropertyBag.set_ Item(String key, String value) at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro pertyBag(String key, Object value, IPropertyBag propertyBag) --- End of inner exception stack trace --- at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro pertyBag(String key, Object value, IPropertyBag propertyBag) at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig .SetTypeMappingsList(List`1 typeMappings) at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig .RemoveTypeMapping[T](String key) at ConsoleFeatureInstallTest.Program.Main(String[] args) in C:\Temp\ConsoleFe atureInstallTest\ConsoleFeatureInstallTest\Program.cs:line 24 ---------- Starting config --------------- <?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, Cultur e=neutral, PublicKeyToken=ef4330804b3c4129</FromAssembly> <FromType>Microsoft.Practices.SharePoint.Common.Logging.ILogger, Microsoft.P ractices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4 330804b3c4129</FromType> <ToType>ARTC.SharePoint.InvoiceTracking.PowerShell.PowerShellLogger, ARTC.Sh arePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture=neutral, PublicKey Token=null</ToType> <ToAssembly>ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Cul ture=neutral, PublicKeyToken=null</ToAssembly> <InstantiationType>NewInstanceForEachRequest</InstantiationType> </TypeMapping> </ArrayOfTypeMapping> --------------------------------------------- ******************************************************************************** The debugger then stops on line 441 of ConfigManager.cs with the following exception information: Microsoft.Practices.SharePoint.Common.Configuration.ConfigurationException was unhandled Message=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.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type ILogger, key "" Source=Microsoft.Practices.SharePoint.Common StackTrace: 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 ConsoleFeatureInstallTest.Program.Main(String[] args) in C:\Temp\ConsoleFeatureInstallTest\ConsoleFeatureInstallTest\Program.cs:line 45 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: Microsoft.Practices.ServiceLocation.ActivationException Message=Activation error occured while trying to get instance of type ILogger, key "" Source=Microsoft.Practices.ServiceLocation StackTrace: at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]() at Microsoft.Practices.SharePoint.Common.Configuration.SPFarmPropertyBag.set_Item(String key, String value) at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(String key, Object value, IPropertyBag propertyBag) InnerException: System.IO.FileNotFoundException Message=Could not load file or assembly 'ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Source=mscorlib FileName=ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null FusionLog==== Pre-bind state information === LOG: User = AA\administrator LOG: DisplayName = ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///C:/Temp/ConsoleFeatureInstallTest/ConsoleFeatureInstallTest/bin/Debug/ LOG: Initial PrivatePath = NULL Calling assembly : Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Temp\ConsoleFeatureInstallTest\ConsoleFeatureInstallTest\bin\Debug\ConsoleFeatureInstallTest.vshost.exe.Config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: The same bind was seen before, and was failed with hr = 0x80070002. StackTrace: at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString) at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLocator.CreateInstanceFromTypeMapping(TypeMapping typeMapping) at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLocator.DoGetInstance(Type serviceType, String key) at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) InnerException: ******************************************************************************** Here is the stack trace with a little more detail: > Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(string key = "Microsoft.Practices.SharePoint.Common.TypeMappings", object value = Count = 1, Microsoft.Practices.SharePoint.Common.Configuration.IPropertyBag propertyBag = {Microsoft.Practices.SharePoint.Common.Configuration.SPFarmPropertyBag}) Line 441 C# Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.SetTypeMappingsList(System.Collections.Generic.List<Microsoft.Practices.SharePoint.Common.ServiceLocation.TypeMapping> typeMappings = Count = 1) Line 285 C# Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RegisterTypeMapping<Microsoft.Practices.SharePoint.Common.Logging.ILogger,ConsoleFeatureInstallTest.Program.CustomLogger>(string key = null, Microsoft.Practices.SharePoint.Common.ServiceLocation.InstantiationType instantiationType = NewInstanceForEachRequest) Line 176 C# Microsoft.Practices.SharePoint.Common.dll!Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig.RegisterTypeMapping<Microsoft.Practices.SharePoint.Common.Logging.ILogger,ConsoleFeatureInstallTest.Program.CustomLogger>() Line 137 C# ConsoleFeatureInstallTest.exe!ConsoleFeatureInstallTest.Program.Main(string[] args = {string[0]}) Line 45 C# ******************************************************************************** If this output doesn't come through properly in the comment please e-mail me your address through CodePlex and I'll send it to you via e-mail. Thanks for your time looking at this and best regards, Alex.

ckeyser wrote Aug 10, 2010 at 2:57 PM

Hi Alex,

Looknig at the stack trace I thought this exception might occur, but the console app is catching any exception when it removes a typemapping at that point and should continue to run. At the point at which this exception is thrown the configuration should have already been stored to the farm configuration settings. Can you please let the console app run outside of the debugger and give me the output? This will help me understand better what is going on. I'm dumping information on the config after this error occurs, and attempting to reset the value to something else. I have fixed the issue with the logging message, but I don't want to publish the fix until I'm sure this will solve the full problem. You will still need to recycle the WFE's after updating farm configuration. With site level configuration, we flush the cached values periodically so this is not needed. I've added a backlog item to use the same approach with the farm in the future.
Thanks,
Chris

Thanks,
Chris

ckeyser wrote Aug 10, 2010 at 3:05 PM

Hi Alex,

I also tested the repro you provided and it worked fine with my fix. I'm still worried though that the type isn't getting unregistered for you. It should get unregistered even when the exception is thrown so I'd like to continue to try and figure out what is going on.

Chris

arangas wrote Aug 10, 2010 at 11:54 PM

Oops, sorry Chris. Here is the output of the first run outside of the debugger:

Microsoft.Practices.SharePoint.Common.Configuration.ConfigurationException: Conf
igsetting with key 'Microsoft.Practices.SharePoint.Common.TypeMappings' could no
t be set 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationC
onfigData' with type 'Microsoft.Practices.SharePoint.Common.ServiceLocation.Serv
iceLocationConfigData'. The technical exception was: Microsoft.Practices.Service
Location.ActivationException: Activation error occured while trying to get insta
nce of type ILogger, key "" ---> Microsoft.Practices.ServiceLocation.ActivationE
xception: Activation error occured while trying to get instance of type ILogger,
key "" ---> System.IO.FileNotFoundException: Could not load file or assembly 'A
RTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture=neutral, Pub
licKeyToken=null' or one of its dependencies. The system cannot find the file sp
ecified.
File name: 'ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture
=neutral, PublicKeyToken=null'
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boo
lean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence
assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence as
semblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLoc
ator.CreateInstanceFromTypeMapping(TypeMapping typeMapping)
at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLoc
ator.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Typ
e serviceType, String key)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].

--- End of inner exception stack trace ---
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Typ
e serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstanceTSe rvice
at Microsoft.Practices.SharePoint.Common.Configuration.SPFarmPropertyBag.set

Item(String key, String value)
at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro
pertyBag(String key, Object value, IPropertyBag propertyBag)
--- End of inner exception stack trace ---
at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro
pertyBag(String key, Object value, IPropertyBag propertyBag)
at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig
.SetTypeMappingsList(List`1 typeMappings)
at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig
.RemoveTypeMapping[T](String key)
at ConsoleFeatureInstallTest.Program.Main(String[] args) in C:\Temp\ConsoleFe
atureInstallTest\ConsoleFeatureInstallTest\Program.cs:line 24
---------- Starting config ---------------
<?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, Cultur
e=neutral, PublicKeyToken=ef4330804b3c4129</FromAssembly>
<FromType>Microsoft.Practices.SharePoint.Common.Logging.ILogger, Microsoft.P
ractices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4
330804b3c4129</FromType>
<ToType>ARTC.SharePoint.InvoiceTracking.PowerShell.PowerShellLogger, ARTC.Sh
arePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture=neutral, PublicKey
Token=null</ToType>
<ToAssembly>ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Cul
ture=neutral, PublicKeyToken=null</ToAssembly>
<InstantiationType>NewInstanceForEachRequest</InstantiationType>
</TypeMapping>

</ArrayOfTypeMapping>

Unhandled Exception: Microsoft.Practices.SharePoint.Common.Configuration.Configu
rationException: Configsetting with key 'Microsoft.Practices.SharePoint.Common.T
ypeMappings' could not be set 'Microsoft.Practices.SharePoint.Common.ServiceLoca
tion.ServiceLocationConfigData' with type 'Microsoft.Practices.SharePoint.Common
.ServiceLocation.ServiceLocationConfigData'. The technical exception was: Micros
oft.Practices.ServiceLocation.ActivationException: Activation error occured whil
e trying to get instance of type ILogger, key "" ---> Microsoft.Practices.Servic
eLocation.ActivationException: Activation error occured while trying to get inst
ance of type ILogger, key "" ---> System.IO.FileNotFoundException: Could not loa
d file or assembly 'ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system ca
nnot find the file specified.
File name: 'ARTC.SharePoint.InvoiceTracking.PowerShell, Version=1.0.0.0, Culture
=neutral, PublicKeyToken=null'
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boo
lean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence
assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence as
semblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLoc
ator.CreateInstanceFromTypeMapping(TypeMapping typeMapping)
at Microsoft.Practices.SharePoint.Common.ServiceLocation.ActivatingServiceLoc
ator.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Typ
e serviceType, String key)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].

--- End of inner exception stack trace ---
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Typ
e serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstanceTSe rvice
at Microsoft.Practices.SharePoint.Common.Configuration.SPFarmPropertyBag.set

Item(String key, String value)
at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro
pertyBag(String key, Object value, IPropertyBag propertyBag)
--- End of inner exception stack trace ---
at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro
pertyBag(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
.RegisterTypeMappingTFrom,TTo
at ConsoleFeatureInstallTest.Program.Main(String[] args) in C:\Temp\ConsoleFe
atureInstallTest\ConsoleFeatureInstallTest\Program.cs:line 45

It doesn't appear to have worked. Subsequent executions give the same result.

Please let me know how I can help out next.

ckeyser wrote Aug 11, 2010 at 2:57 PM

Hi Alex,
Have you had a chance to run the console application? We want to close out and publish a couple of doc and code fixes for August, and I'd like to verify this has been resolved first.

Thanks,
Chris

arangas wrote Aug 11, 2010 at 11:26 PM

Hi Chris,

My previous message was it. Is there something I'm missing?

Thanks, Alex.

ckeyser wrote Aug 12, 2010 at 2:57 AM

Hi Alex,
I'd like you to let this run without the debugger. It will catch the exceptions, and output some configuration information I'm looking for. What you have posted is the exception I expected to happen and am catching in the console application. Please run the console app, let the exceptions be caught and give me the output of the console app.

arangas wrote Aug 13, 2010 at 12:05 AM

Hi Chris,

That is what I'm doing, but the problem is there is no exception handler covering line 45 which fails and crashes the whole app, meaning no further output.

One of the issues seems to be that RemoveTypeMapping() cannot handle the removal of types that no longer exist on the system. Bear with me, I'm going to look at the code and try to see what's happening (without error handling for readability):
    public virtual void RemoveTypeMapping<T>(string key)
    {
        // Read existing config
        List<TypeMapping> typeMappings = GetConfigData();

        // Remove type mapping we no longer need
        foreach (TypeMapping mapping in typeMappings.ToArray())
        {
            if (mapping.FromType == typeof(T).AssemblyQualifiedName
                && mapping.Key == key)
            {
                typeMappings.Remove(mapping);
            }
        }

        // Store updated type mappings
        // EXCEPTION
        SetTypeMappingsList(typeMappings);
    }

Then looking at SetTypeMappingsList():
    private void SetTypeMappingsList(List<TypeMapping> typeMappings)
    {
        // Get property bag for storing type mapping config
        IPropertyBag propertyBag = GetPropertyBag();

        if (propertyBag != null)
        {
            // Store type mappings in list configData
            var configData = new ServiceLocationConfigData(typeMappings);
            configData.LastUpdate = DateTime.Now;

            // Update the property bag from what's in the list
            // EXCEPTION
            Manager.SetInPropertyBag(GetConfigKey(), configData, propertyBag);
        }
    }

All looks good so far, now SetInPropertyBag() with important variable values included in comments:
    public void SetInPropertyBag(string key, object value, IPropertyBag propertyBag)
    {
        string fullKey = GetNamespacedKey(key); // fullKey == "PnP.Config.Key.Microsoft.Practices.SharePoint.Common.TypeMappings"
        string valueAsString = null;
        string typeName = "(null)";

            if (value == null)
            {
                propertyBag[fullKey] = null;
            }
            else
            {
                // Now serialize the value. and set it in the PropertyBag. 
                valueAsString = Serializer.Serialize(value.GetType(), value);
                // RemoveTypeMapping(): valueAsString == "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfTypeMapping xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" />"
                // RegisterTypeMapping(): "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfTypeMapping xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <TypeMapping>\r\n    <FromAssembly>Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</FromAssembly>\r\n    <FromType>Microsoft.Practices.SharePoint.Common.Logging.ILogger, Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129</FromType>\r\n    <ToType>ConsoleFeatureInstallTest.Program+CustomLogger, ConsoleFeatureInstallTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</ToType>\r\n    <ToAssembly>ConsoleFeatureInstallTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</ToAssembly>\r\n    <InstantiationType>NewInstanceForEachRequest</InstantiationType>\r\n  </TypeMapping>\r\n</ArrayOfTypeMapping>"
            }

            bool savedConfig = false;
            Exception savedException = null;

            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;  // EXCEPTION
...


So what happens in the set():
        set
        {
            // EXCEPTION - type not found for logger
            var logger = SharePointServiceLocator.GetCurrent().GetInstance<ILogger>();
...


Generally it seems that the problem is that the service locator is referencing its own logger, which may or may not be valid. If it isn't then the exception occurs.

One option to resolving this could be to only throw exceptions from the internals of the service locator code and only use the service locator itself at the highest levels once it is certain that the type mappings are registered correctly. The downside is it wouldn't let give you as accurate or informative logging information.


From this I should be able to give you definitive repro steps:
  1. Create a custom logger from ILogger
  2. Register this type
  3. Now exclude the type from your project so it can no longer be found
  4. Try and use RemoveTypeMapping or RegisterTypeMapping.
Hope this helps, Alex.

ckeyser wrote Aug 13, 2010 at 1:45 AM

Hi Alex,

I had reposted a version that did have the exception catching logic in it. The version currently posted catches the exception. I just re-downloaded it, and line 45 is a register operation:
        cfg.RegisterTypeMapping<ILogger, CustomLogger>();
However this seems to still be centered around the issue I've fixed. Please do me a favor and modify the following method to see if things then work. If they do, we can stop worrying about the differences in our environments, and I get the fix out for the problem. Please put replace the code in SPFarmPropertyBag methods with following code and see if it then works. I can then go ahead and get this fix out.
   /// <summary>
    /// Gets or sets a value based on the key. If the value is not defined in this PropertyBag, it will look in it's
    /// parent property bag.
    /// </summary>
    /// <value></value>
    /// <returns>The config value defined in the property bag. </returns>
    public string this[string key]
    {
        [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
        [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
        get
        {
            FarmSettingStore store = GetSettingStore();
            if (store == null)
                return null;

            rrLock.EnterReadLock();

            try
            {
                if (!store.Settings.ContainsKey(key))
                    return null;

                return store.Settings[key];
            }
            finally
            {
                rrLock.ExitReadLock();
            }
        }
        [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
        [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
        set
        {
            rrLock.EnterWriteLock();

            try
            {
                //intentionally nested, both cases getting a write lock, is safe and ensures no race.
                //Force the reload of the persisted object, which minimizes chances of a failure due
                // to a concurrency failure.
                Reset();
                FarmSettingStore store = GetWriteSettingStore();

                store.Settings[key] = value;
                store.Update();
            }
            catch (SPUpdatedConcurrencyException)
            {
                Reset();
                throw;
            }
            finally
            {
                rrLock.ExitWriteLock();
            }


        }
    }

    /// <summary>
    /// Remove a particular config setting from this property bag.
    /// </summary>
    /// <param name="key">The key to remove</param>
    [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
    [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
    public void Remove(string key)
    {
        rrLock.EnterWriteLock();
        try
        {
            //intentionally nested, both cases getting a write lock, is safe and ensures no race.
            //Force the reload of the persisted object, which minimizes chances of a failure due
            // to a concurrency failure.

            Reset();
            FarmSettingStore store = GetWriteSettingStore();


            if (store.Settings.ContainsKey(key))
            {
                store.Settings.Remove(key);
                store.Update();
            }
        }
        catch (SPUpdatedConcurrencyException)
        {
            Reset();
            throw;
        }
        finally
        {
            rrLock.ExitWriteLock();
        }
    }

arangas wrote Aug 13, 2010 at 6:14 AM

Hmmm, I downloaded it again and must be getting a cached copy. Anyway, I applied the changes (also renaming GetSettingStore() to GetWriteSettingStore() so it would compile) and the problem about the non-existent logger so that seems to be fixed. However it is now giving a concurrency error. I'm not sure how it got into that state or how to get it out of it. Here is the ULS output: 08/13/2010 15:39:29.15 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Unified Logging Service b8fx High ULS Init Completed (ConsoleFeatureInstallTest.exe, onetnative.dll) 08/13/2010 15:39:31.55 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Database 8u1d High Flushing connection pool 'Data Source=aasp2010dev;Initial Catalog=SPConfig;Integrated Security=True;Enlist=False;Connect Timeout=15' 08/13/2010 15:39:31.55 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation General avew High An application domain named ConsoleFeatureInstallTest.exe has just been loaded. 08/13/2010 15:39:31.68 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Monitoring b4ly High Leaving Monitored Scope (Initializing Admin OM). Execution Time=2270.20024273896 08/13/2010 15:39:32.02 ConsoleFeatureInstallTest.exe (0x0D0C) 0x1418 SharePoint Foundation Object Cache 9j6t High SPXmlDocCache cache parameters are: high water mark 10485760 bytes, low water mark 5242880 bytes, interval 180000 ms 08/13/2010 15:39:32.23 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 75bd High UpdatedConcurrencyException: The object FarmSettingStore Name=_pnpFarmConfig_ was updated by another user. Determine if these changes will conflict, resolve any differences, and reapply the second change. This error may also indicate a programming error caused by obtaining two copies of the same object in a single thread. Previous update information: User: AA\administrator Process:ConsoleFeatureInstallTest (4380) Machine:AASP2010DEV Time:August 13, 2010 03:21:48.0000 Current update information: User: AA\administrator Process:ConsoleFeatureInstallTest (3340) Machine:AASP2010DEV Time:August 13, 2010 03:39:32.0566 08/13/2010 15:39:32.26 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 8xqy High ConcurrencyException: Old Version : 18005 New Version : 18005 08/13/2010 15:39:32.73 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C Patterns and Practices SharePoint Guidance 0000 High ConfigManager: Failure saving config to 'CurrentSPFarm' level, retry count: '0', key: 'Microsoft.Practices.SharePoint.Common.TypeMappings' 08/13/2010 15:39:32.85 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 75bd High UpdatedConcurrencyException: The object FarmSettingStore Name=_pnpFarmConfig_ was updated by another user. Determine if these changes will conflict, resolve any differences, and reapply the second change. This error may also indicate a programming error caused by obtaining two copies of the same object in a single thread. Previous update information: User: AA\administrator Process:ConsoleFeatureInstallTest (4380) Machine:AASP2010DEV Time:August 13, 2010 03:21:48.0000 Current update information: User: AA\administrator Process:ConsoleFeatureInstallTest (3340) Machine:AASP2010DEV Time:August 13, 2010 03:39:32.7324 08/13/2010 15:39:32.85 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 8xqy High ConcurrencyException: Old Version : 18005 New Version : 18005 08/13/2010 15:39:32.86 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C Patterns and Practices SharePoint Guidance 0000 High ConfigManager: Failure saving config to 'CurrentSPFarm' level, retry count: '1', key: 'Microsoft.Practices.SharePoint.Common.TypeMappings' 08/13/2010 15:39:32.94 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 75bd High UpdatedConcurrencyException: The object FarmSettingStore Name=_pnpFarmConfig_ was updated by another user. Determine if these changes will conflict, resolve any differences, and reapply the second change. This error may also indicate a programming error caused by obtaining two copies of the same object in a single thread. Previous update information: User: AA\administrator Process:ConsoleFeatureInstallTest (4380) Machine:AASP2010DEV Time:August 13, 2010 03:21:48.0000 Current update information: User: AA\administrator Process:ConsoleFeatureInstallTest (3340) Machine:AASP2010DEV Time:August 13, 2010 03:39:32.8642 08/13/2010 15:39:32.94 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 8xqy High ConcurrencyException: Old Version : 18005 New Version : 18005 08/13/2010 15:39:32.94 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C Patterns and Practices SharePoint Guidance 0000 High ConfigManager: Failure saving config to 'CurrentSPFarm' level, retry count: '2', key: 'Microsoft.Practices.SharePoint.Common.TypeMappings' 08/13/2010 15:39:33.29 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 75bd High UpdatedConcurrencyException: The object FarmSettingStore Name=_pnpFarmConfig_ was updated by another user. Determine if these changes will conflict, resolve any differences, and reapply the second change. This error may also indicate a programming error caused by obtaining two copies of the same object in a single thread. Previous update information: User: AA\administrator Process:ConsoleFeatureInstallTest (4380) Machine:AASP2010DEV Time:August 13, 2010 03:21:48.0000 Current update information: User: AA\administrator Process:ConsoleFeatureInstallTest (3340) Machine:AASP2010DEV Time:August 13, 2010 03:39:33.1709 08/13/2010 15:39:33.29 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 8xqy High ConcurrencyException: Old Version : 18005 New Version : 18005 08/13/2010 15:39:33.29 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C Patterns and Practices SharePoint Guidance 0000 High ConfigManager: Failure saving config to 'CurrentSPFarm' level, retry count: '0', key: 'Microsoft.Practices.SharePoint.Common.TypeMappings' 08/13/2010 15:39:33.49 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 75bd High UpdatedConcurrencyException: The object FarmSettingStore Name=_pnpFarmConfig_ was updated by another user. Determine if these changes will conflict, resolve any differences, and reapply the second change. This error may also indicate a programming error caused by obtaining two copies of the same object in a single thread. Previous update information: User: AA\administrator Process:ConsoleFeatureInstallTest (4380) Machine:AASP2010DEV Time:August 13, 2010 03:21:48.0000 Current update information: User: AA\administrator Process:ConsoleFeatureInstallTest (3340) Machine:AASP2010DEV Time:August 13, 2010 03:39:33.3965 08/13/2010 15:39:33.49 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 8xqy High ConcurrencyException: Old Version : 18005 New Version : 18005 08/13/2010 15:39:33.49 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C Patterns and Practices SharePoint Guidance 0000 High ConfigManager: Failure saving config to 'CurrentSPFarm' level, retry count: '1', key: 'Microsoft.Practices.SharePoint.Common.TypeMappings' 08/13/2010 15:39:33.63 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 75bd High UpdatedConcurrencyException: The object FarmSettingStore Name=_pnpFarmConfig_ was updated by another user. Determine if these changes will conflict, resolve any differences, and reapply the second change. This error may also indicate a programming error caused by obtaining two copies of the same object in a single thread. Previous update information: User: AA\administrator Process:ConsoleFeatureInstallTest (4380) Machine:AASP2010DEV Time:August 13, 2010 03:21:48.0000 Current update information: User: AA\administrator Process:ConsoleFeatureInstallTest (3340) Machine:AASP2010DEV Time:August 13, 2010 03:39:33.5029 08/13/2010 15:39:33.63 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C SharePoint Foundation Topology 8xqy High ConcurrencyException: Old Version : 18005 New Version : 18005 08/13/2010 15:39:33.63 ConsoleFeatureInstallTest.exe (0x0D0C) 0x0E4C Patterns and Practices SharePoint Guidance 0000 High ConfigManager: Failure saving config to 'CurrentSPFarm' level, retry count: '2', key: 'Microsoft.Practices.SharePoint.Common.TypeMappings' Here is the console app output until it crashes: Microsoft.Practices.SharePoint.Common.Configuration.ConfigurationException: Conf igsetting with key 'Microsoft.Practices.SharePoint.Common.TypeMappings' could no t be set 'Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocationC onfigData' with type 'Microsoft.Practices.SharePoint.Common.ServiceLocation.Serv iceLocationConfigData'. The technical exception was: Microsoft.SharePoint.Admini stration.SPUpdatedConcurrencyException: An update conflict has occurred, and you must re-try this action. The object FarmSettingStore Name=_pnpFarmConfig_ was u pdated by AA\administrator, in the ConsoleFeatureInstallTest (4380) process, on machine AASP2010DEV. View the tracing log for more information about the confli ct. ---> Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException: An u pdate conflict has occurred, and you must re-try this action. The object FarmSet tingStore Name=_pnpFarmConfig_ was updated by AA\administrator, in the ConsoleFe atureInstallTest (4380) process, on machine AASP2010DEV. View the tracing log f or more information about the conflict. at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro pertyBag(String key, Object value, IPropertyBag propertyBag) --- End of inner exception stack trace --- at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro pertyBag(String key, Object value, IPropertyBag propertyBag) at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig .SetTypeMappingsList(List`1 typeMappings) at Microsoft.Practices.SharePoint.Common.ServiceLocation.ServiceLocatorConfig .RemoveTypeMapping[T](String key) at ConsoleFeatureInstallTest.Program.Main(String[] args) in C:\Temp\Bugs\patt erns and practices\ConsoleFeatureInstallTest\ConsoleFeatureInstallTest\Program.c s:line 24 ---------- Starting config --------------- <?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" /> --------------------------------------------- Unhandled Exception: Microsoft.Practices.SharePoint.Common.Configuration.Configu rationException: Configsetting with key 'Microsoft.Practices.SharePoint.Common.T ypeMappings' could not be set 'Microsoft.Practices.SharePoint.Common.ServiceLoca tion.ServiceLocationConfigData' with type 'Microsoft.Practices.SharePoint.Common .ServiceLocation.ServiceLocationConfigData'. The technical exception was: Micros oft.SharePoint.Administration.SPUpdatedConcurrencyException: An update conflict has occurred, and you must re-try this action. The object FarmSettingStore Name= _pnpFarmConfig_ was updated by AA\administrator, in the ConsoleFeatureInstallTes t (4380) process, on machine AASP2010DEV. View the tracing log for more informa tion about the conflict. ---> Microsoft.SharePoint.Administration.SPUpdatedConcu rrencyException: An update conflict has occurred, and you must re-try this actio n. The object FarmSettingStore Name=_pnpFarmConfig_ was updated by AA\administra tor, in the ConsoleFeatureInstallTest (4380) process, on machine AASP2010DEV. V iew the tracing log for more information about the conflict. at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro pertyBag(String key, Object value, IPropertyBag propertyBag) --- End of inner exception stack trace --- at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPro pertyBag(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 ConsoleFeatureInstallTest.Program.Main(String[] args) in C:\Temp\Bugs\patt erns and practices\ConsoleFeatureInstallTest\ConsoleFeatureInstallTest\Program.c s:line 45

ckeyser wrote Aug 13, 2010 at 2:50 PM

Hi Alex,

You shouldn't have to rename the method. You don't have the latest release. That change reflects an update made to the library released at the end of July to MSDN (it fixed an issue with hierarchical search for an value that was not configured when a setting had never been stored to the web app level or farm level).

In order to make that change the concurrency model had to be updated among other things. You will need to get the latest off of MSDN to fix it. I plan on going forward with the fix, I'm pretty certain it will remedy your issue.
Thanks,

Chris

arangas wrote Aug 16, 2010 at 5:22 AM

Hi Chris,

Sorry to bug you again but I've updated to the latest release and still have the concurrency issue. I've checked thoroughly that the old build is nowhere on my system, including removing it from the GAC and checking I'm building against the latest assemblies. Hopefully it's because my system got into an inconsistent state with debugging this issue, rather than a bug.

The errors in the ULS are:

ConcurrencyException: Old Version : 18005 New Version : 18005
SPFarmPropertyBag: Concurrency update failure when updating Key: 'PnP.Config.Key.Microsoft.Practices.SharePoint.DiagnosticAreas'
ConfigManager: Failure saving config to 'CurrentSPFarm' level, retry count: '2', key: 'Microsoft.Practices.SharePoint.DiagnosticAreas'

Can you please advise how I can reset the concurrency state?

Thank you,

Alex.

arangas wrote Aug 16, 2010 at 11:43 PM

I was able to fix this myself by creating a console app with the single line:

FarmSettingStore.DeleteStore(SPFarm.Local);

ckeyser wrote Aug 17, 2010 at 12:32 PM

Hi Alex,

That is a brute force way to do it by removing all configuration but I was to try and figure out why you were having problems with the state you were in. The concurrency update exception is surprising, we retry several times and under heavy load in our testing we are not getting any concurrency exceptions with the locking and read-back logic that was implemented, even in a farm with several WFE's.

Does everything now seem to be working?

Chris

ckeyser wrote Aug 17, 2010 at 12:35 PM

Alex,

It looks like the last concurrency exception you posted related to adding logging areas and categories. Can you post your code for that area? Did this clear after you deleted the farm store? There could be an error in how you are sequencing your calls, but I'd like to take a look to see if we can make the implementation more robust.

Chris

wrote Aug 17, 2010 at 12:50 PM

arangas wrote Aug 18, 2010 at 12:53 AM

Chris, I realise the DeleteStore() is heavy handed but I needed to quickly get back to a working state and that resolved the concurrency errors. I am having problems with registering the areas and categories though which I'll raise as a separate issue.

Thanks, Alex.

wrote Feb 21, 2013 at 11:32 PM

wrote May 16, 2013 at 11:03 AM

wrote May 16, 2013 at 11:03 AM

wrote Jun 14, 2013 at 7:26 AM