栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

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

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

对应的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:emportantCodeSourceglassSolutionJinShiReportRptListFrm1.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 ,如果只是少量的,则可以重新创建报表来为这个错误做出妥协。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/910294.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号