You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity升级后安卓端SharePoint CSOM读取列表报错:找不到ContentTypeId默认构造函数

问题:Unity升级后Android端读取SharePoint列表报MissingMethodException错误

将Unity从2022.3.2f1升级至2023.2.10f1后,开发的连接SharePoint Online的Android应用出现异常:仅在安卓设备运行时读取SharePoint列表会报错MissingMethodException: Default constructor not found for type Microsoft.SharePoint.Client.ContentTypeId,该错误仅出现在Android Logcat运行时日志中。

项目导入升级无异常,Windows的Unity编辑器中运行完全正常,仅打包到安卓设备时出现问题。其他SharePoint功能(文件上传/下载、获取在线文件夹目录、写入列表)均正常,仅读取列表时出错,该代码已正常运行一年多,旧版本构建仍可正常使用。

代码示例:

public static void ReadListItem(string site, string listName, string camlViewXml)
{
    clientContext = GetNewClientContext(site);
    Microsoft.SharePoint.Client.List myList = clientContext.Web.Lists.GetByTitle(listName);
    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml = camlViewXml;
    tempListColl = myList.GetItems(camlQuery);

    clientContext.Load(tempListColl);

    try
    {
        clientContext.ExecuteQuery();
    }
    catch (WebException ex)
    {
        Debug.Log("List Update stopped:" + ex.Message);
    }
    catch (ServerException ex) { Debug.Log("List Update stopped:" + ex.Message); return; }
}

即使通过异步Task调用也会触发错误。旧版本Unity使用.NET Standard 2.0可正常运行,新版本仅支持.NET Standard 2.1,猜测问题与.dll引用和依赖的.NET Standard 2.1兼容性有关,已通过Nuget更新包但问题仍存在,请求排查建议。


排查建议
  • 检查IL2CPP代码裁剪设置:Unity 2023.x的IL2CPP默认裁剪规则可能更严格,ContentTypeId的无参构造函数被误裁剪。在Player Settings > Other Settings > Optimization中,将Managed Stripping Level设为Disabled或Low测试;或者添加链接器配置文件(link.xml),显式保留目标类型的构造函数:
    <linker>
      <assembly fullname="Microsoft.SharePoint.Client">
        <type fullname="Microsoft.SharePoint.Client.ContentTypeId" preserve="all"/>
      </assembly>
    </linker>
    
  • 确认CSOM包的.NET Standard 2.1兼容性:确保使用的Microsoft.SharePointOnline.CSOM包是支持.NET Standard 2.1的最新版本(至少16.0.24110.12000及以上),部分旧版本CSOM的ContentTypeId可能未在.NET Standard 2.1环境下正确暴露无参构造函数。
  • 统一.NET环境配置:在Player Settings > Other Settings > Configuration中,确认Api Compatibility Level确实设置为.NET Standard 2.1,且所有依赖DLL都针对该版本编译,避免混合.NET Standard版本导致的兼容性冲突。
  • 验证构造函数可用性:在代码中显式调用new ContentTypeId()测试,看是否在Android端触发同样错误,以此确认是构造函数缺失还是仅在列表读取时的反射调用问题。
  • 分析IL2CPP编译日志:查看打包时的IL2CPP日志,搜索ContentTypeId相关条目,确认是否有被裁剪的提示,定位具体裁剪原因。

内容的提问来源于stack exchange,提问作者Ian Latham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 16:00:21