错误:ValueFactory尝试访问此实例的Value属性 [英] Error: ValueFactory attempted to access the Value property of this instance
问题描述
源文件: c:\ Projects \ WaterfrontSeattle.org \ src \ Orchard \ Logging \ OrchardLog4netLogger.cs
Source File: 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中学到的是,当我们尝试访问惰性值时会发生此类错误. Orchard论坛在Codeplex上发布的一些帖子表明,这意味着该模块已过期,并且需要更新才能正常工作.一些Orchard Gallery帖子建议清除Orchard缓存作为修复.这些都不适合我们.
Research
From DuckDuckGoing, here is what we've learned, this type of error happens when we attempt to access a Lazy Value. Some Orchard Forum posts on Codeplex indicate that this means the module is out-of-date and that it needs an update to work. Some Orchard Gallery posts suggest clearing the Orchard cache as a fix. Neither of those were true for us.
- 删除App_Data .
- 从所有位置删除模块.
- 重新创建网站.
- 还原数据库.
- 从Visual Studio的程序包管理器"中安装模块.
- Delete App_Data.
- Remove the module from all locations.
- Recreate Website.
- Restore the database.
- Install the module from Visual Studio's Package Manager.
验尸
看来,解决方法中最重要的部分是删除App_Data. App_Data内部是什么导致错误?我们之前曾尝试删除cache.dat文件,但没有成功. App_Data中还有什么可以删除的?
Post-mortem
It seems that the most important part of the workaround was deleting App_Data. What was inside App_Data that lead to the error? We had previously tried deleting the cache.dat file without success. What else is there in App_Data that we could have deleted?
- https://orchard.codeplex.com/discussions/400331
- https://orchard.codeplex.com/discussions/402150
- https://orchardimagegallery.codeplex.com/workitem/24
- http://gallery.orchardproject.net/List/Modules/Orchard.Module.Four2n.MiniProfiler
- https://orchard.codeplex.com/discussions/400331
- https://orchard.codeplex.com/discussions/402150
- https://orchardimagegallery.codeplex.com/workitem/24
- http://gallery.orchardproject.net/List/Modules/Orchard.Module.Four2n.MiniProfiler
推荐答案
OP的解决方案只是一种解决方法.这个问题在其GitHub问题线程中得到了很好的解释:
The OP's solution is just a workaround. This problem was well explained in its GitHub issue thread:
如果任何租户的外壳在创建时抛出(在
DefaultOrchardHost.CreateAndActivateShells()
),例外是 应该用OrchardLog4netLogger
记录.但是,记录 方法还尝试记录当前的shell名称,该名称是通过以下方式获得的 未能初始化的同一ShellSettings
,有效地强制 重新初始化.这导致递归,最终以InvalidOperationException:
ValueFactory attempted to access the
Value
property of this instance.
由于ShellSettings
延迟初始化 方法调用自己的Lazy<>.Value
.这有两个作用.首先,它 隐藏原始异常,用覆盖InvalidOperationException
,这使潜在问题更加棘手 进行调试.其次,由于在Lazy<>.CreateValue()
上引发了异常 在每次调用时都被缓存并重新抛出,这使租户 在Orchard重新启动之前无法使用.
If any tenant's shell throws on creation (in
DefaultOrchardHost.CreateAndActivateShells()
), the exception is supposed to be logged withOrchardLog4netLogger
. However, logging methods try also to log current shell name, which is obtained through the sameShellSettings
that failed to initialize, effectively forcing it to re-initialize. This leads to recursion, which ends inInvalidOperationException:
ValueFactory attempted to access the
Value
property of this instance.
due toShellSettings
lazy initialization method calling its ownLazy<>.Value
. This has two effects. First, it hides the original exception, overwriting it withInvalidOperationException
, which makes the underlying problem harder to debug. Second, since the exceptions thrown onLazy<>.CreateValue()
are cached and re-thrown on every invocation, this makes the tenant unusable until Orchard is restarted.
这个问题已经被好几个人解决,包括一个类似的SO问题的答案:在OrchardLog4netLogger.cs
替换中>
This was solved by several people, including 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团队确认这将成为自下一版以来框架核心的一部分.无论如何,还有其他几个人确认它可以正常工作.
In the GitHub discussion, we are currently waiting for the Orchard team to confirm this will become part of the framework core since the next version. Anyway, several other people confirmed it works.
这篇关于错误:ValueFactory尝试访问此实例的Value属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!