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

fik*_*fik 4 c# rdlc winforms fody-costura

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

我也尝试手动嵌入dll,但仍然出现相同的错误。

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

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

任何帮助将不胜感激。谢谢。

小智 5

我今天遇到同样的问题。基于内部异常,似乎报告查看器需要获取其相关 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 ---
Run Code Online (Sandbox Code Playgroud)

经过反复试验,我发现要使报告查看器正常工作,需要从 Fody/Costura 中排除“Microsoft.ReportViewer.ProcessingObjectModel”和“Microsoft.ReportViewer.Common”。以下是我正在使用的 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>
Run Code Online (Sandbox Code Playgroud)