InvalidOperationException in my Lazy<> value factory

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<>.


This has also happened to me with circular dependencies, so if these steps lead you nowhere, try double checking the stacktrace and verifying that there are no circular dependencies.


ValueFactory attempted to access the Value property of this instance.

It may help somebody, I was able to fix that error by inspecting my entire ValueFactory procedure. In my example, I was creating a simple model and the linked it with some other data but during the linking process I was accessing the Value property in a singleton and that caused the error.

So accessing the Value of a Lazy object inside the ValueFactory throws such an error. As the error message is already indicating ;-)