【问题标题】:Error: ValueFactory attempted to access the Value property of this instance错误:ValueFactory 试图访问此实例的 Value 属性
【发布时间】:2014-11-27 00:28:02
【问题描述】:

错误

源文件: c:\Projects\WaterfrontSeattle.org\src\Orchard\Logging\OrchardLog4netLogger.cs

行: 63

来源错误:

Line 61: // Load the log4net thread with additional properties if they are available
Line 62: protected internal void AddExtendedThreadInfo() {
Line 63: if (_shellSettings.Value != null) {
Line 64:     ThreadContext.Properties["Tenant"] = _shellSettings.Value.Name;
Line 65: }

研究

从 DuckDuckGoing 中,我们了解到,当我们尝试访问惰性值时会发生这种类型的错误。 Codeplex 上的一些 Orchard 论坛帖子表明,这意味着该模块已过时,需要更新才能工作。一些 Orchard Gallery 帖子建议清除 Orchard 缓存作为修复。这些对我们来说都不是真的。

我们的解决方法

  1. 删除 App_Data
  2. 从所有位置移除模块。
  3. 重新创建网站。
  4. 恢复数据库。
  5. 从 Visual Studio 的包管理器安装模块。

验尸

似乎解决方法中最重要的部分是删除 App_Data。导致错误的 App_Data 内部是什么?我们之前曾尝试删除 cache.dat 文件但没有成功。 App_Data 中还有什么我们可以删除的?

另见

【问题讨论】:

    标签: c# orchardcms-1.8


    【解决方案1】:

    OP's solution 只是一种解决方法。这个问题在its GitHub issue thread中有很好的解释:

    如果任何租户的 shell 在创建时抛出(在 DefaultOrchardHost.CreateAndActivateShells()),例外是 应该用OrchardLog4netLogger 记录。然而,记录 方法还尝试记录当前的 shell 名称,该名称是通过 相同的ShellSettings 未能初始化,有效地强制 它重新初始化。这导致递归,其结束于 InvalidOperationException:ValueFactory attempted to access theValue property of this instance. 由于 ShellSettings 延迟初始化 方法调用它自己的Lazy<>.Value。这有两个效果。首先,它 隐藏原始异常,用 InvalidOperationException,这使得潜在的问题变得更加困难 调试。二、由于Lazy<>.CreateValue()上抛出的异常 被缓存并在每次调用时重新抛出,这使得租户 在重新启动 Orchard 之前无法使用。

    这个问题被几个人解决了,包括an answer of a similar SO question: in OrchardLog4netLogger.cs replace

    _shellSettings = new Lazy<ShellSettings>(LoadSettings);
    

    _shellSettings = new Lazy<ShellSettings>(LoadSettings,
         System.Threading.LazyThreadSafetyMode.PublicationOnly);
    

    在 GitHub 讨论中,我们目前正在等待 Orchard 团队确认这将成为下一个版本以来框架核心的一部分。无论如何,其他几个人确认它有效。

    【讨论】:

      【解决方案2】:

      在解决 Orchard 错误时,有助于缩小错误的位置:

      1. App_Data
      2. 源代码,和/或
      3. 数据库

      删除 App_Data 文件夹并将源代码和数据库重置/恢复到一切正常的时间。如果您可以一次执行这些操作,那将有助于隔离错误 位置。

      在我们的例子中,问题出在 App_Data

      【讨论】:

        猜你喜欢
        • 2015-03-19
        • 1970-01-01
        • 2010-11-21
        • 2021-05-21
        • 2021-06-01
        • 1970-01-01
        • 2017-09-03
        • 1970-01-01
        • 2016-07-19
        相关资源
        最近更新 更多