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

.NET 8(arm64)AWS Lambda中Telerik Reporting报MissingMethodException

问题背景

使用public.ecr.aws/lambda/dotnet:8-arm64基础镜像,将集成Telerik Reporting的.NET 8应用部署至AWS Lambda。本地构建与发布无异常,但Lambda运行时抛出如下错误:

System.MissingMethodException: Type: Telerik.Reporting.ReportSerialization.Current.ReportSerializable`1[Telerik.Reporting.Report]
   at Telerik.Reporting.Serialization.ObjectReader.CreateInstance(Type type, String name)
   at Telerik.Reporting.Serialization.ObjectReader.CreateInstance(Type type)
   at Telerik.Reporting.Serialization.ObjectReader.ReadObject(Type type)
   at Telerik.Reporting.Serialization.ObjectReader.ReadXmlElement(String name)
   at Telerik.Reporting.Serialization.ObjectReader.Deserialize(IResourceHandler handler)
   at Telerik.Reporting.XmlSerialization.XmlSerializerBase.Deserialize(XmlReader reader, IResourceHandler resourceHandler)
   at Telerik.Reporting.XmlSerialization.ReportXmlSerializer.Deserialize(Stream stream, IResourceHandler resourceHandler)
   at Telerik.Reporting.ReportPackager.UnpackageDocument(Stream packageStream)
   at Telerik.Reporting.Processing.UriReportDocumentResolver.Resolve(IProcessingContext context, UriReportSource rs)
   at Telerik.Reporting.Processing.ReportDocumentResolver`1.Telerik.Reporting.Processing.IReportDocumentResolver.Resolve(IProcessingContext context, ReportSource rs)
   at Telerik.Reporting.Processing.ReportDocumentResolver.Resolve(IProcessingContext context, ReportSource source)

使用的Dockerfile

# Base runtime image for AWS Lambda with .NET 8 (arm64)
FROM public.ecr.aws/lambda/dotnet:8-arm64 AS base

# Build stage with .NET SDK for arm64
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG NUGET_USERNAME=''
ARG NUGET_PASSWORD=''
ARG VERSION=0.0.0-dev
ARG PROJECT_DIR=my-project
ARG ADD_DEV_SOURCES=off
ENV ARTIFACTORY_USERNAME=${NUGET_USERNAME}
ENV ARTIFACTORY_PASSWORD=${NUGET_PASSWORD}

WORKDIR /build
COPY Reports.Lambda/NuGet.Config .
COPY Reports.Lambda/*.csproj Reports.Lambda/
COPY Reports.Engine/*.csproj Reports.Engine/
WORKDIR /build/Reports.Lambda
RUN dotnet restore --packages /src/nuget_packages -v n

WORKDIR /build
COPY Reports.Lambda/ Reports.Lambda/
COPY Reports.Engine/ Reports.Engine/
COPY ${PROJECT_DIR}/Server/Reports/ Reports.Lambda/Server/Reports/
WORKDIR /build/Reports.Lambda
RUN dotnet build --no-restore -c Release -p:Version=${VERSION}
RUN dotnet publish --no-restore -c Release -p:Version=${VERSION} -o /app/publish
COPY ${PROJECT_DIR}/Server/Reports /app/publish/Server/Reports

FROM base AS final
RUN dnf update -y
RUN dnf install -y fontconfig libicu
COPY fonts /var/task/fonts
COPY Reports.Lambda/font-config-local.conf /etc/fonts/local.conf
RUN fc-cache -svf
WORKDIR /var/task
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=0
COPY --from=build /app/publish/ .
CMD ["Reports.Lambda::Reports.Lambda.Function::FunctionHandlerAsync"]

已执行的排查操作

  • 安装了必要系统库fontconfig、libicu
  • 复制自定义字体并通过fc-cache重建字体缓存
  • 配置DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=0启用完整全球化支持

待解决问题

  1. AWS Lambda环境中引发MissingMethodException的原因是什么?
  2. Telerik Reporting、.NET 8与AWS Lambda运行时之间是否存在兼容性问题?
  3. 如何确保Telerik Reporting的所有依赖项都正确包含在Lambda部署包中?

问题解答

1. MissingMethodException的触发原因

这个错误核心是Telerik Reporting序列化组件无法找到或实例化泛型类型ReportSerializable<T>,常见诱因包括:

  • 部署包中缺失Telerik Reporting的部分依赖程序集,尤其是序列化相关的私有或附属组件
  • 构建与运行时架构不匹配:使用$BUILDPLATFORM跨架构构建,但Lambda为arm64环境,部分依赖未正确编译为arm64版本
  • Release发布的裁剪优化:.NET 8默认启用裁剪,若未配置Telerik组件的裁剪豁免,会移除序列化所需的类型或方法

2. 三者的兼容性问题

Telerik Reporting官方已支持.NET 8和AWS Lambda环境,但arm64架构下需注意:

  • 仅Telerik Reporting 17.0及以上版本正式支持.NET 8,旧版本存在兼容性问题
  • Lambda的arm64运行时(Amazon Linux 2)要求所有依赖提供arm64原生版本,部分旧版Telerik组件仅提供x64版本,会引发加载失败
  • 序列化逻辑在Lambda的受限环境中,若依赖路径或权限配置不当,会触发类型加载异常

3. 确保所有依赖正确打包的方法

针对当前场景,可通过以下步骤修复:

  • 禁用裁剪优化:在dotnet publish命令中添加参数-p:PublishTrimmed=false,避免Telerik序列化类型被误裁剪
  • 强制arm64构建:将构建阶段的--platform=$BUILDPLATFORM改为--platform=linux/arm64,确保所有依赖编译为arm64版本,消除跨架构不兼容
  • 验证依赖完整性:发布完成后检查/app/publish目录,确认包含所有Telerik相关dll(如Telerik.Reporting.dll、Telerik.Reporting.XmlSerialization.dll等),缺失则检查NuGet引用是否完整
  • 显式引用附属组件:在项目文件中显式引用Telerik Reporting的所有附属组件,避免依赖项被自动排除
  • 配置报表资源路径:确保.trdp/.trdx报表文件设置为Copy to Output Directory,避免运行时找不到报表文件

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 09:48:11