首页 > 解决方案 > 尽管没有引用,但无法加载文件或程序集“Microsoft.ReportViewer.WebForms”

问题描述

我在我的 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.net-assemblyreportviewer

解决方案


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

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

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


推荐阅读