winForm下,fastReport.net 从.net framework 升级到.net5遇到的错误“Operation is not supported on this platform.”

博客讲述了在将FastReport.net从.NET Framework升级到.NET 5过程中遇到的问题,即某些旧报表文件在预览或打印时报Operation is not supported on this platform.错误。原因是微软的CodeDomProvider.CompileAssemblyFromFile方法在.NET 5中不再支持WinForms平台。尽管FastReport团队未提供替代方案,但新创建的报表文件不受影响。建议拥有大量旧报表的用户暂不升级到.NET 5,或重新设计问题报表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对应的fastReport.net的.net framework 版本是fastReport.net 2016.4.4.0

对应的fastReport.net的.net5版本是fastReport.net 2021.2.8.0

反复跟踪调试,甚至反编绎查看fastreport.dll文件的官方源码后,得出的结果是:

fastreport.net 从FrameWork 升级到.net5后,旧有的一些报表文件,有的可以正常使用,有的则在预览或打印的时候报错,“Operation is not supported on this platform.”我仔查询了一下,是由于报表内部使用了微软System.CodeDom.Compiler库文件的CodeDomProvider.CompileAssemblyFromFile(CompilerParameters, String[]) 方法,如下图:

 ex.StackTrace 的详情如下:

   在 Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
   在 Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
   在 Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)
   在 System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources)
   在 FastReport.Code.AssemblyDescriptor.InternalCompile(CompilerParameters cp, CompilerResults& cr)
   在 FastReport.Code.AssemblyDescriptor.InternalCompile()
   在 FastReport.Code.AssemblyDescriptor.Compile()
   在 FastReport.Report.Compile()
   在 FastReport.Report.Prepare(Boolean append)
   在 FastReport.Report.Prepare()
   在 FastReport.Report.Show(Boolean modal, IWin32Window owner)
   在 JinShiReport.RptListFrm.btnPrviwer_Click(Object sender, EventArgs e) 在 D:\emportant\CodeSource\glassSolution\JinShiReport\RptListFrm1.cs 中: 第 652 行

上 github 查看得知CodeDomProvider.CompileAssemblyFromFile(CompilerParameters, String[]) 

这个方法并不支持winForm平台。.net runtime 官方源码如下:

runtime/CSharpCodeGenerator.PlatformNotSupported.cs at 86a5b7eafc4699321dae0cb6578fc7e874914e39 · dotnet/runtime (github.com)

using System;
using System.CodeDom.Compiler;

namespace Microsoft.CSharp
{
    internal sealed partial class CSharpCodeGenerator
    {
        private CompilerResults FromFileBatch(CompilerParameters options, string[] fileNames)
        {
            throw new PlatformNotSupportedException();
        }
    }
}

 这样终于查到源头,微软团队不支持,而fastReport 团队没有手动实现一个这样的方法,个人能力还做不到,确实没有办法了。

但是,如果新建一个报表文件进行设计则不存在这种问题。可能fastReport团队内部为了优化或转换等原因,采用了对某些旧的报表文件进行重编绎,这时就会报出这个错误。不过并不是所有的报表文件都要重编绎,所以表现出来就是某些报表文件在升级.net5后正常运行,某些则不行。


最后,建议:winForm的同学们,如果你有大量的旧的报表文件,则暂时不要升级到.net5 ,如果只是少量的,则可以重新创建报表来为这个错误做出妥协。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值