使用 costura 嵌入报表查看器 dll 时出错

Error when embedding report viewer dll using costura

我正在 vs2019 中创建一个 winform 应用程序,通过报表查看器创建报表并且它运行良好。但是,当我使用 Fody/Costura 嵌入 dll 时,报告查看器不知何故给出了一个错误。

我也试过手动嵌入dll,还是出现同样的错误

报告查看器中出现错误消息,

处理本地报表时出错。 报告的定义“无效。 报告处理中出现意外错误。 "Microsoft.Reporting.Services.ReportIntermediateFormat.Persistence.IntermediateFormatVersion" 的类型初始值设定项引发异常。 路径不是合法的形式。

如有任何帮助,我们将不胜感激。谢谢。

我今天遇到了同样的问题。基于内部异常,报表查看器似乎需要获取其相关 dll 的版本才能正常工作。如果嵌入了 dll,报表查看器将无法找到它。

System.ArgumentException: The path is not of a legal form.
   at System.IO.Path.NewNormalizePath(String path, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.Path.GetFullPath(String path)
   at System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(String fileName)
   at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
   at Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.IntermediateFormatVersion.<>c__DisplayClass2_0.<.cctor>b__0()
   at Microsoft.ReportingServices.Diagnostics.RevertImpersonationContext.<>c__DisplayClass1_0.<Run>b__0(Object state)
   at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
   at Microsoft.ReportingServices.Diagnostics.RevertImpersonationContext.Run(ContextBody callback)
   at Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.IntermediateFormatVersion..cctor()
   --- End of inner exception stack trace ---

经过反复试验,我发现要使报表查看器正常工作,'Microsoft.ReportViewer.ProcessingObjectModel' 和 'Microsoft.ReportViewer.Common' 需要从 Fody/Costura 中排除。以下是我正在使用的FodyWeavers.xml。

<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <Costura>
    <ExcludeAssemblies>
      Microsoft.ReportViewer.ProcessingObjectModel
      Microsoft.ReportViewer.Common
    </ExcludeAssemblies>
  </Costura>
</Weavers>