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
ValueFactory attempted to access the Value property of this instance.
Value
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.
I'm just chalking this up as a bug in Visual Studio or their implementation of Lazy<>
.