使用沙盒解决方案或 Web 部件时出现“无法解析类型”错误 (KB5015556)

应用对象
SharePoint Foundation 2013 SP1 SharePoint Server 2016

症状

当您使用沙盒解决方案或 Web 部件时,您可能会在 SharePoint 统一记录系统 (ULS) 日志中收到类似于以下内容的错误消息。 这些消息表明某些沙盒解决方案或 Web 部件被阻止。

对于安装了 2022 年 5 月安全更新的 SharePoint Foundation 2013 和 SharePoint EnterpriseServer 2016:

事件 ID 消息
ajrme 注意: ExecuteRequestInSandBox 调用失败。 System.ArgumentException:类型在 Microsoft.SharePoint.UserCode.SPUserCodeExecutionManager.SPUserCodeSerializationBinder.BindToType (String assemblyName、String typeName)
at
…...
ajlz0 注意: 在 Microsoft.SharePoint.UserCode.SPUserCodeExecutionManager.SPUserCodeSerializationBinder.BindToType (String assemblyName、String typeName)
at
…...

对于安装了 2022 年 6 月安全更新或更高版本的安全更新的 SharePoint Foundation 2013,以及安装了 2022 年 7 月安全更新或更高版本的安全更新的 SharePoint Enterprise Server 2016:

事件 ID 消息
6k389 注意: 无效类型:type=XXXXX;assembly=YYYYY,在 SPUserCodeSerializationBinder 中。 有关详细信息并了解如何解决此错误,请访问 https://go.microsoft.com/fwlink/?LinkId=2196531。
ajrme 注意: ExecuteRequestInSandBox 调用失败。 System.ArgumentException:类型在 Microsoft.SharePoint.UserCode.SPUserCodeExecutionManager.SPUserCodeSerializationBinder.BindToType (String assemblyName、String typeName)
at
…...
ajlz0 注意: 在 Microsoft.SharePoint.UserCode.SPUserCodeExecutionManager.SPUserCodeSerializationBinder.BindToType (String assemblyName、String typeName)
at
…...

原因

从 2022 年 5 月的安全更新开始,SharePoint 沙盒服务进一步限制了默认情况下允许运行的类型和程序集。

解决方法

要解决此问题,您必须注册 SharePoint 沙盒服务将允许运行的第三方类型或程序集。 请按以下步骤完成此操作:

  1. 对于 SharePoint Foundation 2013,安装 2022 年 6 月的安全更新或更高版本的安全更新。 对于 SharePoint EnterpriseServer 2016,安装 2022 年 7 月的安全更新或更高版本的安全更新。

  2. 使用受影响的沙盒解决方案或 Web 部件来触发问题。

  3. 打开 SharePoint ULS 日志并查找事件 ID“6K389”。 您将找到带有该事件 ID 的以下消息:

    注意

    SPUserCodeSerializationBinder 中,无效类型:类型 = XXXXX;程序集 = YYYYY。 有关详细信息并了解如何解决此错误,请访问 https://go.microsoft.com/fwlink/?LinkId=2196531。

  4. 注意被阻止的类型和程序集。

  5. 打开沙盒解决方案或 Web 部件所在的 Web 应用程序的 web.config 文件。 web.config 的路径通常如下所示:

    C:\inetpub\wwwroot\wss\VirtualDirectories\<web 应用程序端口>

  6. 在 configuration/SharePoint/SafeMode 部分添加 AllowedListItems 元素。

  7. 在 AllowedListItems 元素内,添加一个 AllowedItem 元素,并将 Name 属性设置为 AllowedSandboxType,格式如下:

  • 若要取消阻止特定类型,请使用 Type 属性添加元素,如下所示:

    <AllowedItem Name="AllowedSandboxType" Type="XXXXX"/>

  • 若要取消阻止特定程序集,请使用 Assembly 属性添加元素,如下所示:

    <AllowedItem Name="AllowedSandboxType" Assembly="YYYYY"/>

下面是一个示例:

<SafeMode  

            MaxControls = "200"   

            CallStack = "false" 

            DirectFileDependencies ="10" 

            TotalFileDependencies = "250" 

            AllowPageLevelTrace = "false" 

            ControlCompatMode="false" 

            > 

            <PageParserPaths> 

            </PageParserPaths> 

         <AllowedListItems> 

     <AllowedItem Name="AllowedSandboxType" Type="Microsoft.SharePoint.Portal.WebControls.RSSAggregatorWebPart, Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=xxxxxx"/> 

             <AllowedItem Name="AllowedSandboxType" Assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxx"/> 

         </AllowedListItems> 

</SafeMode>