出现InvalidOperationException在我的懒惰<>值厂 [英] InvalidOperationException in my Lazy<> value factory

查看:557
本文介绍了出现InvalidOperationException在我的懒惰<>值厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含类似如下的类:

I have a class containing something like the following:

public static class Config
{
    private static Lazy<ConfigSource> _cfgSrc = new Lazy<ConfigSource>(
        () => { /* "ValueFactory" here... */ },
        true);

    public static ConfigSource ConfigSource
    {
        get { return _cfgSrc.Value; }
    }
}

在访问 ConfigSource 属性,我遇到了这个 InvalidOperationException异常

In accessing the ConfigSource property, I encountered this InvalidOperationException:

ValueFactory试图访问这个实例的Value属性。

ValueFactory attempted to access the Value property of this instance.

我看不到我的价值工厂的方法访问属性什么。还有什么可能是引发此异常?这个问题只发生间歇性,但一旦这样做,需要重置IIS来清理异常(这似乎一旦发生被缓存)。

I don't see anything in my "value factory" method that accesses the Value property. Is there anything else that could be triggering this exception? This problem only happens intermittently, but once it does, it takes resetting IIS to clear up the Exception (which appears to be cached once it occurs).

推荐答案

原来,这个错误只是想检查的<$ c中的属性时发生$ C>延迟&LT;&GT; 在Visual Studio调试器。这样做似乎创造了僵局,因为的访问又好像挂线很长一段时间,直到 InvalidOperationException异常终于发生了。我永远无法拦截原异常,所以我无法看到内部堆栈跟踪。

It turned out that this error only occurred when trying to inspect the Value property of the Lazy<> in the Visual Studio debugger. Doing so appeared to create a deadlock because the accessing of Value then seemed to hang the thread for a long time until the InvalidOperationException finally occurred. I could never intercept the original Exception, so I couldn't see the inner stacktrace.

我只是粉化这件事是在Visual Studio中的错误或实施的懒惰&LT;&GT;

I'm just chalking this up as a bug in Visual Studio or their implementation of Lazy<>.

这篇关于出现InvalidOperationException在我的懒惰&LT;&GT;值厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆