Yvand / EntraCP

EntraCP (formerly AzureCP) is a claims provider that connects SharePoint to your Microsoft Entra ID tenant, in federated authentication
https://entracp.yvand.net/
Apache License 2.0
37 stars 8 forks source link

Unexpected error while refreshing configuration #287

Open AlexandrePitaDTT opened 3 days ago

AlexandrePitaDTT commented 3 days ago

Hi, I installed EntraCP with version 26.0.20240627 in Sharepoint. I have installed this version in 2 environments, dev and prod. The EntraCP is working fine in dev; however, in prod, an error occurs when it tries to look up users.

Every time I do ProcessQuery to find users I get a "Not Found Users" empty list, however, there are users and the query should return a list with users. Watching the logs I notice that an exception always happens when the ProcessQuery it's trigger.

Error log:

I analyzed more what could be the problem and found a curious thing. Doing a Select query of EntraCP configuration in SQL SERVER i found an xml object with an stacktrace, that I believe represents an error.

SQL Query: SELECT Id, Name, cast (properties as xml) AS XMLProps FROM Objects WHERE Name = 'EntraCPConfig' XML StackTrace:

<sFld type="String" name="m_LastUpdatedUser">sse</sFld>
<sFld type="String" name="m_LastUpdatedProcess">w3wp (15976)</sFld>
<sFld type="String" name="m_LastUpdatedMachine">EC2AMAZ-IKFL9GV</sFld>
<sFld type="DateTime" name="m_LastUpdatedTime">2024-10-15T17:09:49</sFld>
<sFld type="String" name="m_LastUpdatedStackTrace"> at Microsoft.SharePoint.Administration.LastUpdateInfo.Initialize() at Microsoft.SharePoint.Administration.SPConfigurationDatabase.StoreObject(SPPersistedObject obj, Boolean storeClassIfNecessary, Boolean ensure) at Microsoft.SharePoint.Administration.SPConfigurationDatabase.Microsoft.SharePoint.Administration.ISPPersistedStoreProvider.PutObject(SPPersistedObject persistedObject, Boolean ensure) at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdateCore(Boolean legacyUpdate) at Yvand.EntraClaimsProvider.Configuration.EntraIDProviderConfiguration.Update() at Yvand.EntraClaimsProvider.Configuration.EntraIDProviderConfiguration.ApplySettings(IEntraIDProviderSettings settings, Boolean commitChangesInDatabase) at Yvand.EntraClaimsProvider.Administration.EntraCPUserControl.CommitChanges() at Yvand.EntraClaimsProvider.Administration.GlobalSettingsUserControl.UpdateConfiguration(Boolean commitChanges) at Yvand.EntraClaimsProvider.Administration.GlobalSettingsUserControl.BtnOK_Click(Object sender, EventArgs e) at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(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 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(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 rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext,** IntPtr moduleData, Int32 flags) </sFld>
<sFld type="Int32" name="m_LastUpdatedThreadId">30</sFld>
<sFld type="Guid" name="m_LastUpdatedCorrelationId">e3315aa1-0f29-c0d7-2943-95e7b73b9061</sFld>
</object>

at Microsoft.SharePoint.Administration.LastUpdateInfo.Initialize() at Microsoft.SharePoint.Administration.SPConfigurationDatabase.StoreObject(SPPersistedObject obj, Boolean storeClassIfNecessary, Boolean ensure) at Microsoft.SharePoint.Administration.SPConfigurationDatabase.Microsoft.SharePoint.Administration.ISPPersistedStoreProvider.PutObject(SPPersistedObject persistedObject, Boolean ensure) at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdateCore(Boolean legacyUpdate) at Yvand.EntraClaimsProvider.Configuration.EntraIDProviderConfiguration.Update() at Yvand.EntraClaimsProvider.Configuration.EntraIDProviderConfiguration.ApplySettings(IEntraIDProviderSettings settings, Boolean commitChangesInDatabase) at Yvand.EntraClaimsProvider.Administration.EntraCPUserControl.CommitChanges() at Yvand.EntraClaimsProvider.Administration.GlobalSettingsUserControl.UpdateConfiguration(Boolean commitChanges) at Yvand.EntraClaimsProvider.Administration.GlobalSettingsUserControl.BtnOK_Click(Object sender, EventArgs e) at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(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 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(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 rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)**

The m_LastUpdatedTime is updated always when I make an update to the configuration of EntraCP, even in Sharepoint Central Administration or in Sharepoint Powershell.

I have no idea what could cause the issue, I have check from different environments, and the configuration of EntraCP it's the same. I don't know why this happen only in one Environment.

Yvand commented 3 days ago

@AlexandrePitaDTT this is very typical of a server that does not have the required assembly bindings in its machine.config file. Can you please double check that you completed the step below on all the SharePoint servers in the farm: https://entracp.yvand.net/docs/usage/installation/#set-the-assembly-bindings

AlexandrePitaDTT commented 2 days ago

Hi @Yvand, thank you for your quick response.

I already double-checked the assembly bindings in the machine config file, and I have the same configuration inside the runtime tag of https://github.com/Yvand/EntraCP/blob/master/assembly-bindings.config. I also copied the configuration that I have in my dev environment, that it's working, and paste it to machine.config of prod, and still I have the issue.

In the morning, SharePoint was updated, and the server restarted, and now I don't have the statck trace anymore in the XML object, and it seems that was fixed. Even I update the configuration of EntraCP, doesn't appear the stack trace again. That's good.

However, I still have the error: Unexpected [EntraCP] Unexpected error while refreshing configuration: TypeInitializationException: The type initializer for 'Microsoft.Kiota.Serialization.Json.KiotaJsonSerializationContext' threw an exception every time I query users from my application.

Yvand commented 1 day ago

@AlexandrePitaDTT can you try load the standalone page TroubleshootEntraCP.aspx ? This page will validate if the dependent assemblies load correctly. By default it is available only in the central administration > Security, but you can easily copy it to the LAYOUTS folder of SharePoint, on any server, to call it from any SharePoint web app / site.