VS2019 WinForms发布后无法加载Microsoft.ReportViewer.WinForms程序集
使用Visual Studio 2019搭配.NET Framework 4.7.2开发WinForms项目,报表窗体在Visual Studio中运行正常,但运行bin/debug/app.publish文件夹中的.exe文件时,出现以下错误:
无法加载文件或程序集“Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91”或它的某一个依赖项。系统找不到指定的文件。
文件名称:“Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91”
已尝试安装以下两个NuGet包:
- Corrected.Microsoft.ReportingServices.ReportViewerControl.Winforms 150.1358.0
- Microsoft.ReportingServices.ReportViewerControl.Winforms 150.1537.0
两个包均在项目中添加了以下DLL:
Microsoft.ReportViewer.Common Microsoft.ReportViewer.DataVisualization Microsoft.ReportViewer.Design Microsoft.ReportViewer.ProcessingObjectModel Microsoft.ReportViewer.WinForms
已尝试多种公开资源上的解决方案,但均未解决问题。完整异常信息如下:
************** Exception Text ************** System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified. File name: 'Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' at electric_shop_system.forms.reports_dashboard.InitializeComponent() at electric_shop_system.forms.reports_dashboard..ctor() at electric_shop_system.main.open_reports_Click(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
1. 检查引用的复制本地配置
- 右键项目中的
Microsoft.ReportViewer.WinForms引用 → 属性:- 将复制本地设置为
True; - 确认版本与错误提示的15.0.0.0一致;
- 若勾选了特定版本,需确保版本完全匹配。
- 将复制本地设置为
- 对其他ReportViewer相关DLL(Common、ProcessingObjectModel等)执行相同配置。
2. 手动复制运行时依赖到发布目录
打开解决方案根目录的packages文件夹,找到对应ReportViewer包的安装路径(例如packages\Microsoft.ReportingServices.ReportViewerControl.Winforms.150.1537.0\lib\net40),将以下DLL复制到bin/debug/app.publish目录:
Microsoft.ReportViewer.WinForms.dll Microsoft.ReportViewer.Common.dll Microsoft.ReportViewer.DataVisualization.dll Microsoft.ReportViewer.ProcessingObjectModel.dll
注意:Microsoft.ReportViewer.Design.dll是设计时依赖,运行时无需复制。
3. 添加程序集绑定重定向
如果安装的ReportViewer包版本是150.x.x.x(对应文件版本15.0.x.x),但错误提示查找15.0.0.0,需在app.config中添加绑定重定向:
<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.ReportViewer.WinForms" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-15.0.0.0" newVersion="15.0.1537.0" /> <!-- 替换为你实际安装的包版本号 --> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.ReportViewer.Common" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-15.0.0.0" newVersion="15.0.1537.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
替换newVersion的值为你安装的NuGet包对应的版本号(可在NuGet包管理器中查看)。
4. 修正发布配置的文件包含规则
- 右键项目 → 属性 → 发布 → 应用程序文件:
- 点击显示所有文件,找到所有ReportViewer相关DLL;
- 将它们的发布状态设置为包含,不要选排除或依赖项。
5. 清理并重新发布
- 执行生成 → 清理解决方案;
- 删除项目目录下的
bin和obj文件夹; - 重新生成项目后再次执行发布操作。
内容的提问来源于stack exchange,提问作者Hunar

