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