Operation is not valid due to the current state of the object

Yesterday I had an issue reconfiguring the User Profiles Service Application where got “Operation is not valid due to the current state of the object”

Profile Synchronisation

My customer used SharePoint Active Directory Import and we needed to switch this to SharePoint Profile Synchronisation.

syncoptions

Why? We wanted to import  photos stored in AD into the SharePoint User Profiles using PowerShell. And the

Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation https:/ /mysite

is only supported with profile synchronisation.

First of all I got these messages when I switched the synchronisation type. Every minute a number of these appeared.

PartitionPropertiesCache.RefreshPartitionProperties: Encountered error: System.InvalidOperationException: Operation is not valid due to the current state of the object. ;at
Microsoft.Office.Server.Administration.UserProfileApplication.PartitionPropertiesCache.get_SqlSession() ;at Microsoft.Office.Server.Administration.UserProfileApplication.PartitionPropertiesCache.RefreshPartitionProperties()

I looked at:

  • FIM certificates
  • Try to run the sync on a different server
  • Checked the account used in the services console?
  • Checked for stuck timer jobs?
  • Recreated the user profile service (many times)

None of this worked.

Then I found some additional errors:

User Profile Application: SynchronizeMIIS encounters an exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Office.Server.UserProfiles.UserProfileImportJob.<>c__DisplayClass2.b__1()
at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.b__3()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at Microsoft.Office.Server.UserProfiles.UserProfileImportJob.IsTimerJobRunning(UserProfileApplicationJob timerJob)
at Microsoft.Office.Server.Administration.UserProfileApplication.SynchronizeMIIS()
at Microsoft.Office.Server.Administration.ILMProfileSynchronizationJob.Execute()

Also of the two services involved I found that the Synchronisation Service was stuck in starting

User Profile Service                                    Started    Stop
User Profile Synchronization Service     Starting

Fixing Operation is not valid due to the current state of the object

Then I started to play around with some PowerShell.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

Get-SPServiceInstance | where {$_.TypeName -like “User*”}

This usually returns:

TypeName Status Id
——– —— —
User Profile Synchronization … Online e2212408-5988-439f-9784-db085650e9ac
User Profile Service Online c0b2cca4-f440-43f6-8018-d32b0547eb31

In my case I found that I got 4 services returned.

So for all for services I ran :

Stop-SPServiceInstance <Guid>

Then I started the User Profile Service (in my case both instances)

Start-SPServiceInstance <Guid>

Then I started one of the synchronisation services and all started to work.

Conclusion there must have been a left over user profile service causing problems.


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Avatar of Pieter Veenstra

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@sharepains.com

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains

Subscribe now to keep reading and get access to the full archive.

Continue reading