尽管没有引用,但无法加载文件或程序集 'Microsoft.ReportViewer.WebForms'

Could not load file or assembly 'Microsoft.ReportViewer.WebForms' despite no references

我在我的 ASP.NET 项目中遇到过此错误消息,但这个最新的实例确实让我感到困惑,因为我在我的项目中找不到任何对 ReportViewer 的引用。寻找关于如何弄清楚这是从哪里来的任何建议。以下是堆栈跟踪信息:

    [FileNotFoundException: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +457
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +34
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +729
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +69
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +226
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +73
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +321
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +878

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +525
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +124
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +700

许多 Asp.Net 控件需要报表查看器库的支持才能呈现输出。因此,尝试安装包 Microsoft Report Viewer Redistributable,然后尝试编译解决方案。您可能在安装过​​程中或之后无意中删除了它。

您也可以尝试去检查 GAC [C:\Windows\assembly] 文件夹中是否有 [Microsoft.ReportViewer.WebForms] 和相关程序集。如果找不到,则表明隐式依赖项在您的工作站中不可用。

虽然我一直无法确定为什么会出现上述错误,但我发现了一种解决方法,即从我在该服务器上的其他工作应用程序中将一堆程序集复制到项目的 \bin 文件夹中。这些程序集包括:

Microsoft.ReportViewer.*
Microsoft.AI.Web
Microsoft.ApplicationInsights
Microsoft.AspNet.*

...和其他几个。这仍然困扰着我为什么这是必要的,因为代码不仅在我的开发机器上运行良好,而且在我第一次部署它的另一个测试 Web 服务器上运行良好。如果我的项目没有对这些东西的可验证引用,但仍然依赖于它们,那么我希望发布工具应该确保这些依赖项与我的其余代码一起部署。