When to re-provision the Security Token Service Application in SharePoint

If you’re seeing entries like this in your logs, you might want to re-provision the SecurityTokenServiceApplicationPool

08/18/2018 12:54:02.49	w3wp.exe (0x3624)	0x16B0	SharePoint Foundation	Claims Authentication	8306	Critical	An exception occurred when trying to issue security token: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401).	8f05869e-fd92-7016-1774-7c7232f5d2ba

08/18/2018 12:54:16.57	w3wp.exe (0x3DB0)	0x3EC4	SharePoint Foundation	Runtime	a1yj	Exception	An unhandled exception has occurred. Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401) System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)    Server stack trace:      at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)     at System.ServiceModel.Channels.SocketConnectionInitiator.Connect(Uri uri, TimeSpan timeout)     at System.ServiceModel.Channels.BufferedConnectionInitiator.Connect(Uri uri, TimeSpan timeout)     at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)     at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)     at Microsoft.ApplicationServer.Caching.CacheResolverChannel.Open(TimeSpan timeout)     at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)     at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)    Exception rethrown at [0]:      at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)     at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)     at Microsoft.ApplicationServer.Caching.CacheResolverChannel.OpenDelegate.EndInvoke(IAsyncResult result)     at Microsoft.ApplicationServer.Caching.ChannelContainer.Opened(IAsyncResult ar)     at System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)     at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)     at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()     at System.Threading.ThreadPoolWorkQueue.Dispatch() StackTrace: (null)	9205869e-ad76-7016-1774-7751e815418b

If you’re installing PowerPivot and you are getting an error when installing PowerPivot on SharePoint that reads http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc had an innerException and or an incorrect SOAP address.

 

To reset the STS run the following lines:

$sts = Get-SPServiceApplication | ?{$_ -match "Security"}
$sts.Status
$sts.Provision()

$h = Get-SPServiceHostconfig
$h.Provision()
$services = Get-SPServiceApplication
foreach ($service in $services) { $service.provision();
write-host $service.name} 

Then run IISRESET