【问题标题】:.NET assembly is not loaded from GAC.NET 程序集未从 GAC 加载
【发布时间】:2015-10-27 13:33:40
【问题描述】:

一天中大部分时间我都在用头撞桌子,我这辈子都无法理解这一点。尝试使用它的 Web 应用找不到明显位于全局应用程序缓存中的程序集。我在网上可以找到的所有内容都假定或明确声明无法避免从 GAC 加载,这是全局和强制性行为。然而,就我而言,它似乎失败了。

GAC 中的程序集:

.aspx 页面尝试使用它时出错:

System.Configuration.ConfigurationErrorsException: Could not load file or assembly 'CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral' or one of its dependencies. The system cannot find the file specified. (C:\Program Files\FMS\GeoPortal2\reporting\web.config line 34) ---> System.IO.FileNotFoundException: Could not load file or assembly 'CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral' or one of its dependencies. The system cannot find the file specified.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
   --- End of inner exception stack trace ---
   at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
   at System.Web.Configuration.AssemblyInfo.get_AssemblyInternal()
   at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
   at System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName)
   at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

更新:我尝试将丢失的 .dll 的“复制本地”设置为“true”,以便在构建时将其包含在项目中。现在我得到一个不同的错误:

System.Web.HttpCompileException (0x80004005): c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\geo2\e2a70b87\2b9be05\App_Web_reportviewer.aspx.733fdbe7.njrhyncf.0.cs(254): error CS0433: The type 'CrystalDecisions.Web.CrystalReportViewer' exists in both 'c:\Windows\assembly\GAC_MSIL\CrystalDecisions.Web\13.0.2000.0__692fbea5521e1304\CrystalDecisions.Web.dll' and 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\geo2\e2a70b87\2b9be05\assembly\dl3\4e808648\047538f8_8e06d101\CrystalDecisions.Web.DLL'
   at System.Web.Compilation.AssemblyBuilder.Compile()
   at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
   at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

所以情况是,当 .dll 在项目中时,IIS 发现 GAC 两者,并抱怨冲突。当程序集不在项目中时,IIS 也找不到。此外,尝试打开错误消息显示的 GAC 路径 (c:\Windows\assembly\GAC_MSIL\CrystalDecisions.Web) 会出现“不存在”错误。

我比以前更迷茫了。什么会导致这种奇怪的行为?

【问题讨论】:

  • 您是否已将 CrystalReports(独立包)安装到服务器中?
  • 另外,您是否已将 LOG4NET32 安装到服务器中?不要问我为什么,但我相信这是必要的——至少在我的情况下是这样。

标签: asp.net .net global-assembly-cache


【解决方案1】:

您打开的 GAC 适用于 .NET 2/3/3.5。 .NET 4 及更高版本使用另一个位置。确保在 .NET 4 SDK 或 VS 2010(及更高版本)中使用 gacutil.exe 提示安装程序集。

【讨论】:

  • gacutil.exe 不是一个好的解决方案,因为这个问题出在部署服务器上,它没有(也不应该)有任何开发工具。我怀疑客户是否会同意为此在其生产环境中安装 SDK 或整个 Visual Studio 实例。另外,请查看原帖的更新。
  • @ModusOperandi 你不知道它可以简单地复制到那台机器上并使用吗?无需安装大型 SDK。当然,Microsoft 有用于 Web 应用程序部署的 Web Deploy,它可以解决此类问题。
  • 好的,谢谢,我会试试的。但我仍然想了解问题所在,尤其是考虑到我在更新中写的内容。这似乎是一个非常奇怪的行为,我想正确修复它,而不是仅仅手动解决第三方安装程序。
  • @ModusOperandi 您通过使用像这样的第三方组件进入黑暗。只有遵循其供应商文档,您才能找到一种安全且受支持的方法来部署应用程序,而我的建议只是一种肮脏的黑客攻击。你的更新如果不触碰就更难理解,所以我不会对此发表太多评论。
【解决方案2】:

我不能确定具体是什么帮助,但我卸载并重新安装了所有与 CrystalReports 相关的内容,然后检查了 .config 文件中与 CrystalReports 相关的所有内容,调整了所有看起来不合适的内容。具体来说,我在它开始工作之前修复的最后一件事是 PublicKeyToken=692FBEA5521E1304CrystalDecisions.Web 程序集参考中丢失。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 1970-01-01
    • 2010-11-13
    • 2011-01-27
    • 1970-01-01
    相关资源
    最近更新 更多